Transparent mode bug lazarus / 31-LCL ---------------------------------------------------------------------- jamie · 2019-11-29 01:49 It took me some time to figure out what was not working because all the examples I tried all over failed to work.. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button4Click(Sender: TObject);var  Bmp: TBitmap;begin  Bmp := TBitmap.Create;  try    bmp.PixelFormat := pf32bit;;  // << does not work in 32 bit formats, all others are ok.    Bmp.Width := 100;    Bmp.Height := 100;    Bmp.Transparent := TRUE;    Bmp.TransparentColor := clBlack;    Bmp.Canvas.Brush.Color := clBlack;    Bmp.Canvas.FillRect(Rect(0, 0, Bmp.Width, Bmp.Height));    Bmp.Canvas.Brush.Color := clRed;    Bmp.Canvas.FillRect(Rect(42, 42, 20, 20));    Canvas.Draw(12, 12, Bmp);  finally    Bmp.Free;  end;end;                     This code is suppose to draw a red box on the left corner of the form, with my systems WIn10, it draws black for the background and the Red box on top.  If I change the pixelformat to anything else other than 32 bit, it works.. I mean I can do it all the way down to 1 bit and it still draws transparent..  Is this a known bug ? ---------------------------------------------------------------------- winni · 2019-11-29 02:20 Hi! I've got  no win10, I can't test it but two hints: * I would never use clBlack as Transparentcolor - it is just zero or $000000 - if that looks better. Default is clFuchsia and I think it is okay because it is so ugly that you can't use it otherwise. (Exception: german Telecom) * Give the coordinates of a rect from left to right and from top to bottom - in good software it saves time  and in bad software  it wont work otherwise.  The  Rect implementation in Laz does exange x1 and x2, also y1 and y2 until  x1,y1 are topleft and x2,y2 are bottomright - but you can't always rely on this. Jamie fighting with win10! What about a real OS? Winni ---------------------------------------------------------------------- jamie · 2019-11-29 02:23 I am not so sure it is win10 because I just compiled a test app on my old W2k PC using Delphi 3 and a 32 bit test, moved it over to this PC as an EXE, ran it and it works.  So you tell me ?  Next I need to go the otherway… but something tells me its going to fail. ---------------------------------------------------------------------- winni · 2019-11-29 02:33 Hi! I can only stuck around in the  fog: Is it a 64 Bit machine? And I tell you there were two reasons to make my graphics with BGRA: The one is that TBitmap is awful slow. And the second is that I always had trouble with transparency. Then I detected the great abilities of BGRA. Just a hint. Winni ---------------------------------------------------------------------- winni · 2019-11-29 02:46 Hi! Another trick. The transpareny of the TBitmap was added late - in the early days there was no  transparency - or only with lousy tricks. Easier is working with  png because it has transpareny by default. So instead of a bitmap use  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i png : TPortableNetworkGraphic; Everything else stays the same. Winni ---------------------------------------------------------------------- jamie · 2019-11-29 03:07 What do you think PNG uses for rendering ?  anyways, I have Laz 2.0.0 installed on the W2k Pc, I compiled, linked the test app and that basically does the same things as what WIn10 does, it fails with 32 bit mode..   However, on that one, I had to move the point of where I set the TransparentColor because if I set it just prior to canvas.Textout, …. it does not work at all in any bit level.  If  transparentColor just after I set the pixelformat and Size of the image, it then works all the way up to 24 bit but not 32 bit.  It almost behaves like there is some uninitialized variable in the Tbitmap class because it seems a bit random..  Maybe others can run the test block I posted where and trye the Pixelformat := pf32bit; to see if it works  This is of course a 32 bit app on a WIn10 64 PC.. but since it fails also with my W2k and D3 works just fine there, there is some greater issue. ---------------------------------------------------------------------- winni · 2019-11-29 03:45 STOP ! Don't search in the depth of the sources: Rect (42,42.20.20) does not work!!!!! (Linux64, gtk2) Rect (20,20,42,42)  works !!! Nice little red square. And: Use png: TPortableNetworkGraphic And: Use clFuchsia as transparent color Otherwise I have the same trouble like you. Red square in attachment! As I said: BGRA ....... Winni ---------------------------------------------------------------------- jamie · 2019-11-29 15:33 Its not the Red square that is the issue, its the fact that its painting the full interior of the bitmap to the surface instead of being transparent around the square.  Delphi works 100% for this starting at 1 bit up 32 bits This is a serous issue, the stock GDI should work! I am not concerned about speed at the moment. ---------------------------------------------------------------------- jamie · 2019-11-30 02:13 Well, after hours or debugging I found something. CustomBitmap.RawImageNeeded……  Pf32bit had riqAlpha flag set for an option that is not complete.. it hammers transparency operations  I commented it out..  It works now... I wanted to add that this was a little premature because I did some testing and it appears what the code did was just switch it to a 24 bit image without the flag in it …  So this isn't really fixed yet... Damn.... ---------------------------------------------------------------------- cappe · 2019-11-30 09:54 Hello everybody I saw the image JamieTransparent.png, I would like to ask you but how is the caption of the window (blue color) done? also works with linux or only on windows? ---------------------------------------------------------------------- PascalDragon · 2019-11-30 10:04 Quote from: cappe on November 30, 2019, 10:54:05 amHello everybody I saw the image JamieTransparent.png, I would like to ask you but how is the caption of the window (blue color) done? also works with linux or only on windows? That is his desktop theme on Linux. Not related to Lazarus in any way. ---------------------------------------------------------------------- wp · 2019-11-30 11:18 I tried your code on Win2k with Laz: same black rectangle as with Win10. Doing a lot of such temporary bitmap operations without issues I wonder why I do not see it in my own programs. This is because I do not set the PixelFormat explicity, i.e. it stays at the default pfDevice. Why do you need to request a 32-bit pixelformat? The bitmap format has always been a bit messy regarding transparency, and I remember lots of issues also with Delphi and that there were "DrawTransparent" routines around in several external libs such as JVCL. When I really need true alpha-channel transparency I always use TPortableNetworkGraphic. Lazarus always has been more open towards non-TBitmap images. Delphi7 did not allow png in TListbox, and even Delphi XE 10.3 still rejects png for TBitBtn's glyph. ---------------------------------------------------------------------- jamie · 2019-11-30 16:03 I use the memory image of the 32 bit format with the alpha channel but not for blending but for layering images.  Up to 255 layers can be had by doing this and it's easy to save/load from streams in this manner.  I use the GDI system to manipulate the images and I need to be able to mix them in order as a final image which needs to be shown on a visible canvas as a single image when done using transparency of the final.  Also the transparency needs to work when stacking them.  I have three apps that kind of work with each other moving image files around like this and lots of code attached to them.  Its a program that has been used for quite some time now and I need to keep it as close as possible compileable between Delphi and Lazarus.  Currently I use the ScanLine property to obtain the line pointers and it seems that this all works ok accept the images are not transparently overlaying so its a wash out.  What we need is a property the 32 bit mode to select normal transparent painting when enabled and should be by default or Set to indicate the use of Alpha blend if it ever gets completed. ---------------------------------------------------------------------- wp · 2019-11-30 16:13 Quote from: jamie on November 30, 2019, 05:03:25 pmI use the GDI system to manipulate the images and I need to be able to mix them in order as a final image which needs to be shown on a visible canvas as a single image when done using transparency of the final.  Also the transparency needs to work when stacking them.This description seems to me that you are "abusing" TBitmap. You'll be much happier with optimized imaging libraries such as Graphics32 (Delphi and Lazarus) or BGRABitmap (Lazarus only). For simple image manipulation I use LazIntfImage to provide the alpha channel (https://wiki.freepascal.org/Developing_with_Graphics#Working_ with_TLazIntfImage.2C_TRawImage_and_TLazCanvas). Not available in Delphi, though... ---------------------------------------------------------------------- lainz · 2019-11-30 16:18 Quote from: wp on November 30, 2019, 05:13:46 pmThis description seems to me that you are "abusing" TBitmap. You'll be much happier with optimized imaging libraries such as Graphics32 (Delphi and Lazarus) or BGRABitmap (Lazarus only). That's not true, BGRABitmap works with Delphi, as well BGRAControls provided in this link https://github.com/bgrabitmap/BGRABitmapDelphi ---------------------------------------------------------------------- wp · 2019-11-30 17:01 Thanks for the clarification. ---------------------------------------------------------------------- jamie · 2019-11-30 19:00 There is no abuse of the files, the last two lines of the image are image information and setup info. The last two lines are used because they are actually at the start of the image pile..  Years ago we experimented using classes like TImageList, embedded within a Class that also handled the information Indexes etc,. We found it to be a problem if one of these chucks of info got separated or damaged from the images. Plus it was slowwwwww compared to using a 32 bit image.  I need to keep things on the up and up between the two DEV tools because my people I deal with want it this way incase a fall out happens on one side of the street.  So since there are different apps currently being used on these image files they need to stay the same format.  Conventional image viewers are able to see these files and we have documentation notes on the file structure in case they feel the need to make some sort of repair..  I wanted to add another note that using 32 allows for even bound addressing because we have some code that deals with the image directed for special effects that aren't in the GDI libs.  24 bit was used before at the beginning and it was slow, the 32 bit is larger however, the code generated for it is much faster.