How to create FMX.Graphics.TBitmap with specific pixel format?
Asked Answered
P

0

6

Probably I am missing something, but I can't find a way to create FMX bitmap with a specific pixel format. To be more specific, I need to create FMX.Graphics.TBitmap with pixel format BGR_565. The Constructor doesn't have an option to define PixelFormat. The property PixelFormat is readonly (unlike VCL version of TBitmap).

Parulis answered 12/9, 2017 at 14:50 Comment(6)
It's not a simple task as it seems. I was hoping for hacking TBitmap through TBitmap.Map method where I tried to replace the bitmap data record by a new one created with the desired pixel format. No change (Tokyo).Yeh
What if we create VCL bitmap 1x1 pf16bit, save it to file, load into FM Bitmap and resize? (same for resourcestream storage)Lenard
@Lenard This doesn't work too. When i load 16bit bitmap it is automatically converted to 32bit BGRA. As far as i can see in FMX units, there are always created bitbamp with all default setting and if any pixel processing required, it is done in style pixel-by-pixel. I am starting to suspect that it is not possible at all to create FMX bitmap with pixelformat i need.Parulis
Seems i found how it should work - we can create TBitmapSurface with required PixelFormat (it has PixelFormat as parameter of SetSize function), Then we can call Bitmap.Assign (it supports TBitmapSurface as src). But it doesn't work too, TBitmap.AssignFromSurface is trying to copy source bits with MOVE proc as if it is always 32 bits per pixel (so it will either fail because of access bytes outside of src region or produce garbage in format BGRA).Parulis
Seems FMX in this part is not implemented properly. Will have to try something else (maybe some 3th party lib).Parulis
It seems to be hardcoded now. See e.g. code for Windows, there's used DXGI_FORMAT_B8G8R8A8_UNORM format only.Yeh

© 2022 - 2024 — McMap. All rights reserved.