0

Using Delphi 10.2.3:
I need to decode multiple PNG files in multiple background threads to ensure the UI thread is not freezing while the images are being decoded.

I need access to the RAW RGBA values from the decoded PNG without ever using TBitmap as it's not thread safe under Android.

I've seen references to using JBitmap, but my searches didn't yield any sample code demonstrating actual JBitmap use under Delphi so any help would be appreciated.

J...
  • 30,968
  • 6
  • 66
  • 143
bLight
  • 803
  • 7
  • 23
  • This was fixed (TBitmap main thread affinity) in Tokyo 10.2. If you can upgrade, that's an easy option. If you already have 10.2 and didn't know this was fixed, doubly so (version is always good to know in a question). Otherwise, this maybe seems like a request for a third-party alternative to `TBitmap`, which is off-topic. Unless, once you had that third-party alternative, you would still need help getting the RGBA values from it, but I'm not sure that's what this question is really about. – J... Sep 17 '18 at 11:31
  • 1
    @j... no it's not fixed in Tokyo 10.2 ! it's buggy ... ex: https://quality.embarcadero.com/browse/RSP-19687 – zeus Sep 17 '18 at 12:20
  • @J... I tried using TBitmap first, it triggers exceptions. This topic is not about TBitmap, perhaps the title should have been 'how to use jbitmap to load a png and access the raw RGBA values using delphi'. – bLight Sep 17 '18 at 12:28
  • @loki That QC is about `TTexture`. `TBitmap` [is threadsafe](http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Multi-Threading_for_TBitmap,_TCanvas,_and_TContext3D) as of 10.2. – J... Sep 17 '18 at 12:30
  • @bLight What exceptions? Are you sure TBitmap didn't work because of a framework bug? Likely there was simply an error in your code... – J... Sep 17 '18 at 12:36
  • @J... and what do you think Tbitmap use internally ;) – zeus Sep 17 '18 at 12:49
  • 1
    @loki `TBitmap` uses `TBitmapImage` internally. `TTexture` is in `FMX.Types3D` which is not even referenced in `TBitmap.Graphics`, which houses `TBitmap`. Emba even changed your bug report to a new feature request because `TTexture` has never been guaranteed to be threadsafe (whereas `TBitmap`, as of D10.2, is). – J... Sep 17 '18 at 13:03
  • @J... I posted about my experiences here https://stackoverflow.com/questions/52168940/is-png-decoding-not-thread-safe-under-android and this is with Delphi 10.2.3 – bLight Sep 17 '18 at 13:45
  • @J... just continue a little deeper, what do you think TBitmapImage use internally :) Look TBitmapImage.CreateHandle that call CanvasClass.InitializeBitmap that will call TBitmapCtx.Create and be assured that TBitmapCtx use TTexture ! – zeus Sep 17 '18 at 15:01
  • @loki InitializeBitmap calls the abstract `DoInitializeBitmap`. If you had issues, it must have been with a descendent canvas type that was not threadsafe. TCanvas and TContext3D, in 10.2, are threadsafe. `TBitmapCtx` belongs to `TCustomCanvasGpu` which is not indicated as threadsafe. – J... Sep 17 '18 at 15:15
  • @J... Android and Ios USE ONLY TCustomCanvasGpu (the only one that is available)! So DoInitializeBitmap will OBLIGATORY call FMX.Canvas.GPU DoInitializeBitmap that will use TTexture. So as a conclusion Tbitmap is not multithread under android and ios (it's is in fact also not multithread under windows for some other bug) – zeus Sep 17 '18 at 15:27

0 Answers0