bitblt(Masterbitmap.Canvas.handle, 0, 0, XPixel, YPixel,
bitmap.Canvas.handle, 0, 0, srcand);
you explicitly called Masterbitmap.Canvas.Lock, however you didn’t call bitmap.Canvas.Lock (so you can loose the canvas handle anytime within this call…)
Additionally, you need to consider thread safety within GDI itself: Sharing of any GDI objects between different threads should be avoided at all cost. For example if you select a bitmap into two different device contexts at the same time (but in different threads) you may run into problems within GDI itself…
Please note that older versions of delphi don’t protect against sharing of cached handles (Font, Brush and Pen handles are cached within a global list. This was fixed in an XE3 service pack if I remember correctly).
In short: I’d consider to avoid TCanvas and TBitmap completely if you really need multi-threading. (It’s much easier to be multi-threading safe that way)
2
solved merge paint results in thread bitmap painting