ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Creating a PNG file from Clipboard? Error: Bitmap is not valid

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Aug 29 2024 : 15:46:38
I need to load image data from the clipboard and save it to a PNG image file with PNG_TextValues that I can retrieve later from the PNG file.

Is this the most efficient way if I don't use a TImageEnView?

// test if the clipboard contains image data:
  if ImageEnProc1.CanPasteFromClipboard then
  begin
    CodeSite.Send('CAN PASTE IMAGE');
    var bmp := TIEBitmap.Create;
    try
      var IO := TImageEnIO.CreateFromBitmap(bmp);
      try
        IO.Params.PNG_TextKeys.Add('Author');
        IO.Params.PNG_TextValues.Add('Peter');
        IO.SaveToFilePNG(AFilename); // Error: Bitmap is not valid
      finally
        IO.Free;
      end;
    finally
      bmp.Free;
    end;
  end;


By the way, what is the maximum length of a single PNG_TextValue?
4   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Aug 31 2024 : 01:03:50
Hi Nigel

Thanks for the information.
xequte Posted - Aug 30 2024 : 16:20:38
Hi Peter

The maximum length for a PNG text key is 79 printable Latin characters (ISO 8859-1). There is no explicit maximum length for text values

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Aug 30 2024 : 00:30:01
Hi Nigel

Thanks for the hint!

By the way, is there a maximum length limit of a single PNG_TextValue?
xequte Posted - Aug 29 2024 : 16:40:23
Hi Peter

In your code you create a bitmap but you never fill it with anything, so you get an invalid bitmap error.

Try something like (untested):

  if ImageEnProc1.CanPasteFromClipboard then
  begin
    ImageEnProc1.PasteFromClipboard();
    var IO := TImageEnIO.CreateFromBitmap( ImageEnProc1.AttachedIEBitmap );
    try
      IO.Params.PNG_TextKeys.Add('Author');
      IO.Params.PNG_TextValues.Add('Peter');
      IO.SaveToFilePNG(AFilename); 
    finally
      IO.Free;
    end;
  end;


Though it would be easier with a TImageEnView:

Try something like (untested):

  var iev := TImageEnView.Create( nil);
  try
    if iev.Proc.CanPasteFromClipboard then
    begin
      iev.Proc.PasteFromClipboard();
      iev.IO.Params.PNG_TextKeys.Add('Author');
      iev.IO.Params.PNG_TextValues.Add('Peter');
      iev.IO.SaveToFilePNG(AFilename); 
    end;
  finally
    iev .Free;
  end;


Nigel
Xequte Software
www.imageen.com