Having a hard time finding a way to create a

Having a hard time finding a way to create a 
FMX TBitmap with predefined pixel format in XE3, as I used to do with VCL  setting TBitmap.PixelFormat, just after creating a vcl.TBitmap instance.

Now in Firemonkey this property is read-only :(
I want direct access to bitmap data using the Map method without using GetPixel, SetPixel as this solution does: http://members.adug.org.au/2012/10/05/read-write-image-bitmap-pixels-in-delphi-xe3/ 

The purpose is doing image processing at 32bits fixed pixel format.  work with backbuffer non-visible  bitmap then after all processing is done I can show the result to any canvas no matter the final pixel format. 

Any light on this? Help appreciated!
http://members.adug.org.au/2012/10/05/read-write-image-bitmap-pixels-in-delphi-xe3

Comments

  1. I'm fairly sure that the underlying format is dependent on the canvas class - for example, for the D2D canvas, it's 32-bit ARGB always (ABGR maybe?). So I don't think you can set a custom pixel format, you have to use what the implementation requires. It's very unlikely this would be less than 32-bit, ever, so if that's what you need then using TBitmap would be fine. One other thing you might be able to do is use a library like Graphics32 to draw, and then copy the bitmap data over.

    If you're doing background processing, is this in a thread? If so, using bitmaps in a secondary thread is not guaranteed to work with all FMX canvases.  I would go the Graphics32 route, maybe.

    To access data via Map: I can't find a good blog post right now, but Francois Piette updated some open-source code of mine to use the new Map method, and this could be a good example.  Have a look in https://code.google.com/p/dws-terapixel-explorer/source/browse/Tiles.pas and look at TTile.GenerateBitmap; the Map() code is on about line 135 onwards.

    ReplyDelete
  2. Hi David, thanks for the code.
     I need to work with an offscreen bitmap of 32bits, i can't assume the canvas will be 32bits.   Since I'm creating an empty bitmap at run-time, don't understand why I can't set the pixelFormat.
     Graphics32 seems they only support VCL with no plans to support FireMonkey, that should be for some reason. 
     I already have rendering library focused on fast 32bits pixel rutines, it only need a pointer to 32bit pixel data.  It can work already with DirectDraw, DirectX Surfaces and textures, VCL TBitmap, custom Mem... etc. Now the only one who doesnt want to break is FireMonkey.
      I think I'll have to discard FireMonkey and stay in my comfort zone with VCL :)

    ReplyDelete
  3. If you have a rendering library that works with a pointer to 32-bit data, why not point it at an empty buffer (that you allocate), let it draw, and then copy it to the FMX bitmap using the above code once you're done? That way you keep your current rendering code, and the end result ends up in a FMX bitmap you can use.

    ReplyDelete
  4. hmm.. you are right! I need to convert row by row to the TBitmap format using FMX.PixelFormats.AlphaColorToPixel ... I have to try it, need to test its performance.. But is finally a solution. Thank you!

    ReplyDelete

Post a Comment