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
 How to copy image from TImageEn to TGraphic?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

924 Posts

Posted - Apr 30 2015 :  13:09:47  Show Profile  Reply
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?

PeterPanino

924 Posts

Posted - Apr 30 2015 :  13:36:22  Show Profile  Reply
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;
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 30 2015 :  13:43:12  Show Profile  Reply
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
Go to Top of Page

PeterPanino

924 Posts

Posted - Apr 30 2015 :  13:56:27  Show Profile  Reply
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.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 30 2015 :  14:51:12  Show Profile  Reply
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
Go to Top of Page

PeterPanino

924 Posts

Posted - Apr 30 2015 :  17:56:33  Show Profile  Reply
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: