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
 Problems to understand alpha transparency
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

uko

Germany
31 Posts

Posted - Feb 11 2015 :  03:46:43  Show Profile  Reply
Hi,

it looks like I have problems to full understand the way, alpha transparency is handled by ImageEN.

Let's start with a 32bit standard TBitmap, that has set semi transparency:


  bmp := TBitmap.Create;
  try
    bmp.SetSize(300, 300);
    bmp.PixelFormat := pf32bit;
    bmp.AlphaFormat := afDefined;

    bmp.Canvas.Brush.Color := clRed;
    bmp.Canvas.FillRect(Rect(0,0, bmp.Width, bmp.Height));

    // now set some parts of the image semi-transparent 
    for y := 0 to bmp.Height - 1 do
    begin
      P := bmp.ScanLine[y];
      for x := 0 to bmp.Width - 1 do
      begin
        p^.rgbReserved := (128 + y) mod 255;
        inc(p);
      end;
    end;
  ...


Now my task is: display that bitmap with ImageEnView component (LegacyBitmap is set true)

1) I tried simple assignment: ImageEnView1.Assign(bmp);
This results in the bitmap but without any transparency
2) Next I tried to EnableAlphaChannel:
no change, no transparency
3) Try to copy the alpha values from bitmap to AlphaChannel by hand:

    for y := 0 to ImageEnView1.Bitmap.Height - 1 do
    begin
      P := bmp.ScanLine[y];
      pa := ImageEnView1.AlphaChannel.ScanLine[y];
      for x := 0 to ImageEnView1.Bitmap.Width - 1 do
      begin
        pa^:=  p^.rgbReserved; 
        inc(p);
        inc(pa);
      end;
    end;

Result: still no transparency ?!
4) As a last trial, I set AlphaChannel.Full on false:

    ImageEnView1.Assign(bmp);
    ImageEnView1.EnableAlphaChannel := true;
    ImageEnView1.AlphaChannel.Full := false;

    for y := 0 to ImageEnView1.Bitmap.Height - 1 do
    begin
      P := bmp.ScanLine[y];
      pa := ImageEnView1.AlphaChannel.ScanLine[y];
      for x := 0 to ImageEnView1.Bitmap.Width - 1 do
      begin
        pa^:=  p^.rgbReserved;
        inc(p);
        inc(pa);
      end;
    end; 

Yippie, now the bitmap is shown with alpha transparency!

But now my question is: this looks a little bit complicated and needed a lot of trials to find out. So is there a simpler way to display the bitmap, especially when LegacyBitmap := true?
And why for active LegacyBitmaps, alpha channel is not automatically filled on assigning such a bitmap?

Please add such workflows to documentation!

best regards,
Ulrich

xequte

38614 Posts

Posted - Feb 11 2015 :  14:43:48  Show Profile  Reply
Hi Ulrich

Firstly, why are you using LegacyBitmap? As the name implies, this is only to maintain compatibility with old implementations of ImageEn. You should disable LegacyBitmap for all new projects.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

uko

Germany
31 Posts

Posted - Feb 12 2015 :  01:55:24  Show Profile  Reply
Hi Nigel,

I do this because the help file says to do so?!

quote:

Declaration

property LegacyBitmap: Boolean;

Description

If LegacyBitmap is True, ImageEn uses TBitmap to store the image, otherwise ImageEn uses TIEBitmap.
TIEBitmap handles images using memory mapped file (for large images) or main memory.
This allows handling of large images and to include input/output and image processing in a multi-threaded environment.
Also TIEBitmap supports a larger number of pixel formats (TIEPixelFormat).

Note: LegacyBitmap should be set to true for new applications.



Ok, I will do some test with set to false.

best regards,
Ulrich
Go to Top of Page

uko

Germany
31 Posts

Posted - Feb 12 2015 :  03:12:45  Show Profile  Reply
Nigel,

also when disabling LegacyBitmap, I still have to set the alpha channel by hand and set Full to false to make it work.

So can you show me a sample code what you would do, when you have to assign such a 32bit bitmap to ImageEnView (take the one from initial post)?


Thank you,
Ulrich
Go to Top of Page

xequte

38614 Posts

Posted - Feb 12 2015 :  18:35:32  Show Profile  Reply
quote:
Note: LegacyBitmap should be set to true for new applications.


Yes, that unforunate typo is fixed in recent releases.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

xequte

38614 Posts

Posted - Feb 12 2015 :  19:14:22  Show Profile  Reply
Hi

Newer versions of Delphi support the use of the reserved byte of a TBitmap as an alpha value, but I have not seen 32bit bitmap files that use an alpha channel in use.

You would be better to use TIEBitmap which includes an AlphaChannel.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

uko

Germany
31 Posts

Posted - Feb 13 2015 :  02:54:46  Show Profile  Reply
Hi Nigel,

ok, so for our real world application I will have to implement a proper conversion from TBitmap32 (Graphic32) to TIEBitmap and back persisting the alpha channel [instead of converting to TBitmap and assigning this]. Let's start.
As you asked about 32bit BMP files: the bitmaps I'm working with, are only in memory bitmaps that after processing are stored to PDF, so no need to save them on file.

Thank you,
Ulrich
Go to Top of Page

xequte

38614 Posts

Posted - Feb 13 2015 :  14:28:33  Show Profile  Reply
Yes, sorry Ulrich, I should have lead with this rather than address the issue bit by bit.

If you need to use transparency in ImageEn then you should use a TIEBitmap. You could convert TBitmap32 > TBitmap > TIEBitmap, but that would be unnecessary work, so write a routine to convert TBitmap32 > TIEBitmap.

Let us know if you have any difficulty.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: