Board index » delphi » Layered transparent drawings with TImage

Layered transparent drawings with TImage

Thank you Jens for help on Delphi drawings and Torry's web address.

Meanwhile I have accomplished some more tests with TImage control. I have one 5MB in size bitmap placed in TImage as a background - nontransparent, and the second one - blank/white -
transparent, on which I am trying to draw. Refreshing these tooks approximately 1 (one) second on my 350MHz K6-2 PC, even if there is only a little circle on the second (working) TImage. When I turn off transparent property, all comes just in time, but of course I do not see my background. So, I found that drawing in a transparent layer is very much time consuming operation especially with large, color bitmaps.

Atanas.

 

Re:Layered transparent drawings with TImage


Quote
> So, I found that drawing in a transparent layer is very much time consuming operation especially with large, color bitmaps.

Yes, it is. For such operations I prefer direct access via ScanLine
property, although depending on the graphics driver and card "normal"
operations might be as fast or even faster. It depends very much on what
exactly you do, and sometimes you have to try different ways to find out
what's the best. It is not too difficult to use the ScanLine property if
you use the same PixelFormat for both bitmaps you want to combine (and
the same format for a third bitmap, the resulting one). But this
technique has its limits, too, especially for such big graphics your
machine gets very busy. The broblem is, that even if the ScanLine method
is faster, you have to draw the resulting bitmap to the screen, what
takes additional time. But you really have to try it, to find out what's
the fastest way...

Here a scanline example for 8 bit images (all bitmaps have to be of same
size):

var
  Ptr1,Ptr2,Ptr3: ^Byte;
  x,y: Integer;
begin
  for y := 0 to Bitmap3.Height-1 do begin
    Ptr1 := Bitmap1.ScanLine[y];
    Ptr2 := Bitmap1.ScanLine[y];
    Ptr3 := Bitmap1.ScanLine[y];
    for x := 0 to Bitmap3.Width-1 do begin
      if Ptr2^ = InvisibleColor then Ptr3^ = Ptr1^
      else Ptr3^ := Ptr2^;
      inc (Ptr1);
      inc (Ptr2);
      inc (Ptr3);
    end;
  end;
end;

Jens

Re:Layered transparent drawings with TImage


Have you tried the G32 library? it has a replacement for TImage, all code is
32 bit (Windows GDI is still 16 bit) - it is up to 140 times faster doing
this sort of thing - and it's free. It's at http://www.g32.org/

Quote
"Atanas" <atan...@yahoo.com> wrote in message news:3baf593b$1_2@dnews...

> Thank you Jens for help on Delphi drawings and Torry's web address.

> Meanwhile I have accomplished some more tests with TImage control. I have

one 5MB in size bitmap placed in TImage as a background - nontransparent,
and the second one - blank/white -
Quote
> transparent, on which I am trying to draw. Refreshing these tooks

approximately 1 (one) second on my 350MHz K6-2 PC, even if there is only a
little circle on the second (working) TImage. When I turn off transparent
property, all comes just in time, but of course I do not see my background.
So, I found that drawing in a transparent layer is very much time consuming
operation especially with large, color bitmaps.
Quote

> Atanas.

Other Threads