I'm getting brain fog doing what should be a simple operation - and I know someone is going to point out the blindingly obvious and I'll then proceed to kick myself . I've copied the code from another project, which was written in Delphi, which does work (in Delphi, that is - that project is a tad complicated to port across to Lazarus...not that I'm not going to do it, just not yet!!).
Basically, I'm creating a bitmap (well, loads of them) by building them from scratch, in a byte array - gives me maximum control (or so I thought) and speed. However, I'm wanting them to be transparent (which, I know, generally bitmaps are not). So I've coloured the transparent pixels as magenta ($FF00FF).
Even when I transfer it to a PNG image and save it (specifying as transparent) it still does not do it. The bitmaps can range from any bit depth (1, 4, 8, 16, 24 or 32), but for arguments sake, I'm currently playing with the 8bpp ones (so there is a palette, which I've created). I've tried setting the alpha channel of the transparent colour to $FF, which doesn't do anything either.
The code for display is:
//Load the buffer into the bitmap
ms.Position:=0;
ms.WriteBuffer(buffer[0],Length(buffer));
ms.Position:=0;
SpriteList[x].Image.LoadFromStream(ms);
//Display it
image[x].Picture.Bitmap.Transparent:=True;
image[x].Picture.Bitmap.TransparentColor:=BGColour mod $1000000;
image[x].Picture.Assign(SpriteList[x].Image);
SpriteList[ x ].Image is a TBitmap array and image[ x ] is a TImage array. BGColour is the transparent colour.
I also tried Canvas.Draw(0,0,SpriteList[ x ].Image), but I get nothing. I've also tried setting image[ x ].Transparent to True, which results in a transparent image, just not the bits that should be!!
Earlier in the code (and I'm debating whether this is actually needed or not) I have:
SpriteList[x].Image.Transparent:=True;
SpriteList[x].Image.TransparentColor:=BGColour mod $1000000;
And the code for saving is:
//Save PNG
png:=TPortableNetworkGraphic.Create;
png.Assign(SpriteList[x].Image);
png.Transparent:=True;
png.TransparentColor:=BGColour mod $1000000;
png.SaveToFile(Dir+validateFilename(SpriteList[x].Name)+'.png');
png.Free;
I've seen something about TLazIntfImage (IIRC), but my brain is fogging over trying to think of a way of using it.
This is on Lazarus 2.0.12 on macOS (although will be multiplatform).