Recent

Author Topic: Writing to Image  (Read 3869 times)

rickielynn

  • New Member
  • *
  • Posts: 18
Writing to Image
« on: March 25, 2017, 04:21:51 am »
Can anyone tell me why I can't write to an Image.  Can't even change the color of the image with Image.canvas.brush.color.  Image just stays black.  ie:  procedure below gets called but image remains black.

procedure TForm1.Image6Paint(Sender: TObject);
begin
  form1.button1.caption:='image6 got painted';
  with form1.image6.canvas do
    begin
      Brush.Color := clRed;
      fillrect(form1.image6.left +2,form1.image6.top+20,form1.image6.left +12,form1.image6.top+50);
    end;
end;   

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Writing to Image
« Reply #1 on: March 25, 2017, 06:58:46 am »
Can anyone tell me why I can't write to an Image.  Can't even change the color of the image with Image.canvas.brush.color.  Image just stays black.  ie:  procedure below gets called but image remains black.

procedure TForm1.Image6Paint(Sender: TObject);
begin
  form1.button1.caption:='image6 got painted';
  with form1.image6.canvas do
    begin
      Brush.Color := clRed;
      fillrect(form1.image6.left +2,form1.image6.top+20,form1.image6.left +12,form1.image6.top+50);
    end;
end;
canvas coordinates are not parent based. 0,0 of the canvas is the left,top of the image control on the form try this
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Image1Paint(Sender :TObject);
  2. begin
  3.   //form caption.
  4.   Caption :=   TComponent(Sender).Name + ' got painted';
  5.   with timage(Sender).canvas do
  6.   begin
  7.     Brush.Color := clRed;
  8.     fillrect(2,20,12,50);
  9.   end;
  10. end;
  11.  
one more thing, it seems that the paint event of the timage control has a bug, if there is no picture loaded the inherited paint event is never called so load something.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Writing to Image
« Reply #2 on: March 25, 2017, 03:36:51 pm »
Loading something is also optional, you can give it an empty canvas to work with. That is done by simply giving size to
image6.Picture.Bitmap.Width and Height, and then fill image6.Picture.Bitmap.Canvas with any color you want.

Note the difference between image6.Picture.Canvas and image6.Picture.Bitmap.Canvas. The drawings you do to first one are only temporary. Swipe another window over yours and the drawings would be erased. What you draw on Bitmap.Canvas are permanent and can also be saved into file.

rickielynn

  • New Member
  • *
  • Posts: 18
Re: Writing to Image
« Reply #3 on: March 26, 2017, 11:17:39 pm »
Thank You HeavyUser and User137.  I loaded an empty .bmp to Image then was able to write to it from other procedures using Image.Picture.Bitmap.Canvas. 

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Writing to Image
« Reply #4 on: March 27, 2017, 02:17:07 am »
Thank You HeavyUser and User137.  I loaded an empty .bmp to Image then was able to write to it from other procedures using Image.Picture.Bitmap.Canvas.
to clarify if you are going to use the image.picture.bitmap, which depends on your specifications,  then you simple have to set the dimension to a suitable size
(calling   Image.Picture.Bitmap.SetSize) and an empty bitmap will be created for you.
Smaller exe size and dynamic bitmap size to suite multiple specifications.

 

TinyPortal © 2005-2018