Article

From:
To:
Arnold Reinders
Subject:
Re: How threadsafe is TBitmap
Newsgroup:
embarcadero.public.delphi.graphics

Re: How threadsafe is TBitmap

It's not threadsafe at all.  I had a similar problem where I was rendering 
JPG streams to TBitmaps in a background thread.  The problem actually occurs 
(near as I can tell) when the form is updated.  It trashes any active 
TCanvas's after the refresh.  Someone had posted a work-around involving 
locking the TCanvas, etc but they didn't solve the problem completely.  The 
only truly safe way to work with TBitmaps is in the GUI thread.

I ended up writing my own TBitmapLite class which was not derived from TBitmap and so it didn't inherit the bad behavior. Win32 bitmaps (DIBs) are really not that hard to deal with so the class wasn't all that complex (in fact, looking at the TBitmap code provided most of what I needed).
Erik Turner Melbourne, FL
"Arnold Reinders" <✉somewhere.com> wrote in message 
news:✉forums.codegear.com...
>I am trying to parallellize bitmap operations. This appears to be well
> possible for scanlines. Typical code reads like this:
>
> // inside a tthread derived class do the following in execute
> // where index points at the scanline to be prcoessed
>
> s := source_bitmap.Scanline [index];
> t := target_bitmap.Scanline [index];
> for x := 0 to source_bitmap.Width - 1 do
> begin
>    pixel := s [x];
>    // do something with pixel
>    t [x] := pixel;
> end;
>
> It appears to be threadsafe, each thread processing his own index. I
> have tested this code very often. However, very rarely I get a illegal
> memory read/write. Are there things I overlook? Should I read some
> articles (i couldn't find them)?
>
> Greetings,
>
> Arnold
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Fri, 15 Nov 2024 16:22:33 UTC
Copyright © 2009-2024
HREF Tools Corp.