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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 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
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

914 Posts

Posted - Aug 29 2024 :  15:46:38  Show Profile  Reply
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?

xequte

38457 Posts

Posted - Aug 29 2024 :  16:40:23  Show Profile  Reply
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
Go to Top of Page

PeterPanino

914 Posts

Posted - Aug 30 2024 :  00:30:01  Show Profile  Reply
Hi Nigel

Thanks for the hint!

By the way, is there a maximum length limit of a single PNG_TextValue?
Go to Top of Page

xequte

38457 Posts

Posted - Aug 30 2024 :  16:20:38  Show Profile  Reply
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
Go to Top of Page

PeterPanino

914 Posts

Posted - Aug 31 2024 :  01:03:50  Show Profile  Reply
Hi Nigel

Thanks for the information.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: