TImage problems lazarus / 39-Graphics ---------------------------------------------------------------------- Ross · 2011-05-18 14:52 I am saving the bitmap of a TImage to a MemoryStream as a JPegImage before allowing the user to modify the image.  An UNDO option will load the previous JPegImage in from the saved MemoryStream and assign it to the TImage.Picture.Bitmap.  This seems to work except that after the previous Image is loaded the Pen mode and color don't work as expected. I have attached a small test pas unit that shows this behavior. What am I missing?  Any help is appreciated. Ross ---------------------------------------------------------------------- circular · 2011-05-18 19:28 It doesn't work here either. I've managed to make a real xor rectangle like this : QuotePen.Mode := pmXor;       Pen.Color := clWhite;  But then drawing the final rectangle do not work as expected. This way it should draw black rectangle filled with blue : Quoteprocedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   if Button = mbLeft then   begin     SaveBitmap(Image1.Picture.Bitmap);     DLeft := X;     DTop := Y;     DRight := X;     DBottom := Y;     with Image1.Picture.Bitmap.Canvas do     begin       Pen.Style := psSolid;       Pen.Mode := pmXor;       Pen.Color := clWhite;       Brush.Style := bsClear;     end;   end; end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,   Y: Integer); begin   if ssLeft in Shift then     with Image1.Picture.Bitmap.Canvas do     begin       Rectangle(DLeft, DTop, DRight, DBottom);       DRight := X;       DBottom := Y;       Rectangle(DLeft, DTop, DRight, DBottom);     end; end; procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   if Button = mbLeft then     with Image1.Picture.Bitmap.Canvas do     begin       Rectangle(DLeft, DTop, DRight, DBottom);       Pen.Mode := pmCopy;       Pen.Color := clBlack;       Brush.Style := bsSolid;       brush.Color := clBlue;       Rectangle(DLeft, DTop, X, Y);     end; end; But I get transparent rectangles instead (the background behind the image become visible were the rectangle should be drawn). ---------------------------------------------------------------------- Ross · 2011-05-18 19:52 Hi Circular, Thanks for looking at this.  I can't tell if its something I'm doing wrong or if it is a TImage.Picture.Bitmap.Canvas bug or a bug in the TPen. I had a simular problem with the Canvas.FloodFill method and had to use the WinApi method ExtFloodFill instead to get it to work (pmCopy). ---------------------------------------------------------------------- circular · 2011-05-19 08:31 About the difference when the picture is reloaded, it is because Jpeg doesn't handle transparency, so it becomes black. So I think it is a bug of TImage.Picture.Bitmap.Canvas. I suppose the same program would work well when drawing directly on the form canvas or on a panel (using OnPaint events for mac compatibility).