Author Topic: Canvas.Pixels + ImagingBitmap  (Read 910 times)

Offline davem

  • Imaging User
  • *
  • Posts: 18
    • View Profile
Canvas.Pixels + ImagingBitmap
« on: 20 April 2010, 09:48:03 »
  I got very interesting problem. I manipulate an image using TImageData however then I need to add a text and modify a few pixels manually. So I do this:

        ImgBitmap:=TImagingBitmap.Create;
        ImgBitmap.AssignFromImageData(MainImage);

        // add text (just an example)
        ImgBitmap.Canvas.TextOut(x,y,'some text');

        // set some colors (just an example)
        ImgBitmap.Canvas.Pixels[x,y]:=col;

        // save the changes back to ImageData
        ImgBitmap.AssignToImageData(MainImage);
        ImgBitmap.Free;

  However, my problem is that in some cases (let's say every fifth case) the changes of colors are not visible on the picture when I save it. It seems to me that the Canvas/Handle hasn't been updated yet at the moment I assign the bitmap back to ImageData. Sometimes the part of the image is even partially black. Does anyone have any idea what can be done? I tried to put sleep behind, I tried to use a CriticalSection (it is multithreading appl), I tried to Lock the canvas (although the ImgBitmap is not shared) however nothing works. I also tried to run only one thread but it was the same. Does anyone have any idea?

Offline davem

  • Imaging User
  • *
  • Posts: 18
    • View Profile
Re: Canvas.Pixels + ImagingBitmap
« Reply #1 on: 20 April 2010, 10:12:50 »
Hmm, Synchronize seems to solve the issue. But I don't know why.  :-\

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: Canvas.Pixels + ImagingBitmap
« Reply #2 on: 20 April 2010, 15:33:20 »
What about calling Canvas.Release or Canvas.Refresh after the pixels are set?

Offline davem

  • Imaging User
  • *
  • Posts: 18
    • View Profile
Re: Canvas.Pixels + ImagingBitmap
« Reply #3 on: 20 April 2010, 16:10:02 »
What about calling Canvas.Release or Canvas.Refresh after the pixels are set?

Canvas.Refresh did not help. I haven't tried Canvas.Release.