Hello,
A couple of years ago, I maintained an application that handled JPEG files using the TJPEGImage class in multiple worker threads. We used to have weird AVs and memory leaks, which we traced to the fact that the method TJPEGImage.Draw is notoriously thread-unsafe.
The code snippet is the contents of a file called ThreadSafeJpeg.pas, which solved the issues simply by creating a new class that inherits from TJPEGImage. The only method of the new class is an override to Draw, which wraps the parent method in calls to Lock and Unlock the canvas.
I'm not sure whether it will help, but it's worth a try.
Main Topics
Browse All Topics





by: ciulyPosted on 2008-12-22 at 07:47:12ID: 23227119
TBitmap, TJpegImage are not trehadsafe. they are part of VCL, which is not thread safe :)
in order to use them in a trheaded environment, you must lock the resources, in most cases the canvas.
also, if you are looking for speed, you migt want to consdier using scanline instead of the pixels property (that is, if you are using many pixels from one line).