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
 How to copy image from TImageEn to TGraphic?

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 - Apr 30 2015 : 13:09:47
Hi! I need to load several image files into a TJvRichEdit. TJvRichEdit allows to insert a TGraphic. So I tried the following:

procedure TForm1.btnTestClick(Sender: TObject);
var
  P: TPicture;
begin
  // imgDummy: TImageEn
  imgDummy.IO.LoadFromFileAuto('D:\MyImage1.jpg');

  P := TPicture.Create;
  try
    imgDummy.CopyToBitmapWithAlpha(P.Bitmap, 0, 0);

    // RichEdit: TJvRichEdit
    // RichEdit.InsertGraphic(AGraphic: Vcl.Graphics.TGraphic; Sizeable: Boolean)
    RichEdit.InsertGraphic(P.Graphic, False);
  finally
    P.Free;
  end;
end;


However, this does not work. So how can I copy the image from TImageEn to TGraphic?
5   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Apr 30 2015 : 17:56:33
I have tested it with this code:

imgDummy.IO.LoadFromFileAuto('R:\test.png');
imgDummy.IO.SaveToFilePNG('R:\Saved.png');


Then opened Saved.png in Irfanview and changed the background color in Irfanview several times and restarted Irfanview in between. The saved PNG surely has transparency. It seems that TJvRichEdit does not support PNG transparency.
w2m Posted - Apr 30 2015 : 14:51:12
Are you setting ImageENView1.IO.Params.BMP_HandleTransparency before you load the image? This is critical... If you just look at the image displayed in imageen it will visually show the image has transparency, but in reality it does not have an alphachannel.

If you save the image to disk and then load it into another application without imageen is the transparency maintained? If the image has transparency then the problem is in the receiving component and not imageen.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
PeterPanino Posted - Apr 30 2015 : 13:56:27
Bill, thanks, but the transparency is still not preserved in RichEdit.

The transparency in imgDummy is correct. So it is possible that JvRichEdit does not handle the transparency correctly.
w2m Posted - Apr 30 2015 : 13:43:12
There could be a number of problems that could cause this:

1. Make sure ImageENView1.IO.Params.BMP_HandleTransparency is true before you open and save the file.

2. The bitmap's a;phachannel and transparent color is not set correctly.

BMP files can have up to 32 bits per pixel. This property controls how to interpret the extra byte in the 32 bit word.
When BMP_HandleTransparency is true the extra byte is interpreted as an alpha channel, otherwise it is just ignored.

So if BMP_HandleTransparency = True the image will be displayed in ImageEn with transparency. Whereas if BMP_HandleTransparency = False the transparent color will not be used.

3. It is possible that the bitmap is correct and has an alpha channel with the transparent color set correctly, but the receiving component (JvRichEdit) is the cause of the problem.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
PeterPanino Posted - Apr 30 2015 : 13:36:22
I've now found out how to make it work, however the PNG transparency is not preserved in the RichEdit:

procedure TForm1.btnTestClick(Sender: TObject);
var
  P: TPicture;
begin
  imgDummy.IO.LoadFromFileAuto('R:\test.png');

  P := TPicture.Create;
  try
    P.Bitmap.Assign(imgDummy.IEBitmap.VclBitmap);

    RichEdit.InsertGraphic(P.Graphic, False);

    RichEdit.Lines.Add('');
    RichEdit.Lines.Add('');
  finally
    P.Free;
  end;
end;