peter2005 0 Posted January 30, 2021 hi, for unclear reason delphi does not completely support 32 bit bitmaps. I'm trying to display a 32bit picture data(with alpha channel) in a TImage using TBitmap and have not found a proper way, some parts of the picture are just black. Interesting is that the image although not properly displayed can be saved into a file(image1.Picture.Bitmap.SaveToFile) and works perfectly fine in a picture viewer. Alternative is to use PNG which uses alpha channel however it complicates whole situation since TBitmap is easy to use. I do not want use 3rd-part components or huge libraries ....a code code snippet or an unit to include would be great. Share this post Link to post
David Heffernan 2345 Posted January 30, 2021 Why don't you want to use a third party component? Share this post Link to post
Remy Lebeau 1393 Posted January 30, 2021 (edited) 37 minutes ago, peter2005 said: for unclear reason delphi does not completely support 32 bit bitmaps. Because Windows doesn't have good support for 32bit alpha-channeled bitmaps to begin with. Quote I'm trying to display a 32bit picture data(with alpha channel) in a TImage using TBitmap Good luck with that. Quote Alternative is to use PNG which uses alpha channel however it complicates whole situation since TBitmap is easy to use. What complications does PNG present to you? Are you working with VCL or FMX? The VCL's TPNGImage class is easy to use. FMX's TBitmap can be a bit difficult, depending on what you are trying to do with it. It would really help if you would explain the problem you are having exactly. Edited January 30, 2021 by Remy Lebeau Share this post Link to post
peter2005 0 Posted January 30, 2021 (edited) Quote Because Windows doesn't have good support for 32bit alpha-channeled bitmaps to begin with. Lazarus(free pascal) can handle these bitmaps without any trouble. Quote Why don't you want to use a third party component? I try to avoid installing third party component because it complicates transferring my projects , it has to be installed, even worse when it's for a simple thing like displaying bitmap. Do you have any suggestion of component which could work in my case? Quote What complications does PNG present to you? Are you working with VCL or FMX? The VCL's TPNGImage class is easy to use. FMX's TBitmap can be a bit difficult, depending on what you are trying to do with it. It would really help if you would explain the problem you are having exactly. Probably should not even mention that I use Delphi 7 TBitmap allows access to individual pixels which I need to rearrange, no idea if TPNGImage can do that. Edited January 30, 2021 by peter2005 Share this post Link to post
David Heffernan 2345 Posted January 30, 2021 25 minutes ago, Remy Lebeau said: Because Windows doesn't have good support for 32bit alpha-channeled bitmaps Really? I mean true for bmp files but Windows API supports 32 bit bitmaps fine so far as I know. 2 Share this post Link to post
FPiette 382 Posted January 30, 2021 1 hour ago, peter2005 said: I'm trying to display a 32bit picture data(with alpha channel) in a TImage using TBitmap and have not found a proper way Would you show the code you currently use? It is always easier to answer a question when a minimal reproducible example is given. Provide the code and the required test images. Share this post Link to post
Anders Melander 1782 Posted January 30, 2021 (edited) Works fine for me. Here's a form with two TImage controls, one overlapping the other. The top one contains a 32-bit bitmap with alpha, the bottom a PNG. I have set Image1.Transpartent=False and Image1.Picture.Bitmap.AlphaFormat=afDefined (at run-time) for the bitmap. Edited January 30, 2021 by Anders Melander 1 Share this post Link to post
Anders Melander 1782 Posted January 30, 2021 18 minutes ago, peter2005 said: Probably should not even mention that I use Delphi 7 If you're using Delphi 7 then you will have to use 3rd party components. For example Graphics32 - and better hurry because I plan to drop support for Delphi 7 in Graphics32 the first chance I get. 2 Share this post Link to post
peter2005 0 Posted January 30, 2021 Here is small bmp image. There is a transparent background and greyishblack shadow at the bottom. The background is not the problem Image1.Transpartent=False removes it, but the shadow is always fully black. Can it be loaded and displayed properly? 1.bmp Share this post Link to post
Anders Melander 1782 Posted January 30, 2021 39 minutes ago, peter2005 said: Here is small bmp image. There is a transparent background and greyishblack shadow at the bottom. The background is not the problem Image1.Transpartent=False removes it, but the shadow is always fully black. Can it be loaded and displayed properly? To use alpha transparency you need to set Transparent=False. Here's what it looks like (Delphi 10.3): 2 Share this post Link to post
peter2005 0 Posted January 31, 2021 (edited) 21 hours ago, Anders Melander said: To use alpha transparency you need to set Transparent=False. Here's what it looks like (Delphi 10.3): Yes, it works, thanks. Unfortunately Tbitmap in D7 does not have AlphaFormat property. Edited January 31, 2021 by peter2005 Share this post Link to post
Remy Lebeau 1393 Posted February 1, 2021 On 1/30/2021 at 12:09 PM, Anders Melander said: Image1.Picture.Bitmap.AlphaFormat=afDefined (at run-time) for the bitmap. Oh yeah, I keep forgetting that TBitmap does have some alpha-channel support built-in. Share this post Link to post
Anders Melander 1782 Posted February 1, 2021 1 hour ago, Remy Lebeau said: TBitmap does have some alpha-channel support built-in. Yes but it's a nasty mess. Better than nothing I guess. 1 Share this post Link to post
angusj 126 Posted January 22, 2022 (edited) On 2/2/2021 at 4:02 AM, Anders Melander said: Yes but it's a nasty mess. Better than nothing I guess. I wholeheartedly agree with you Anders that TBitmap.AlphaFormat is broken and should be deprecated. Not only does it not behave in an intuitive manner, but Premultiplying and UnPremultiplying images is (mildly) destructive. But there's another potentially bigger problem - when writing an afDefined Bitmap to stream, UnPreMultiplyAlpha is called and hence the image will no longer be properly rendered. ps: Isn't it fun digging up old threads 😜. Edited January 22, 2022 by angusj typo Share this post Link to post
Anders Melander 1782 Posted January 22, 2022 10 hours ago, angusj said: ps: Isn't it fun digging up old threads 😜. Yeah. It's good to get a reminder of this problem once in a while since it probably won't get fixed. Share this post Link to post