Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-02

Image Copy and Load Fail.

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

최경식

hello everyone.
I Loaded successfully after saving that i drawn.
But i load fail after saving that i copied. (please see below code) This situation occurs in accordance with copy size. Below it is my code and i written some comments.

[My code]
procedure TForm1.Button2Click(Sender: TObject);
begin
  //Drawing
  Image1.Picture.bitmap.PixelFormat := pf32bit;   //Valuable!
  Image1.Picture.bitmap.SetSize(Image1.Width,Image1.Height);
  Image1.Picture.Bitmap.Canvas.TextOut(0,0,'test');
  Image1.Invalidate;  //
  Image1.Picture.Bitmap.SaveToFile('/home/user/Image/drawing.bmp');
  FileListBox1.UpdateFileList;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
  ImagetoSave : TImage;
begin
  ImagetoSave := TImage.Create(Self);
  with ImagetoSave.Picture.Bitmap do
  begin
    PixelFormat := pf32bit;
    SetSize(500,900);                                             // this is where a problem is caused. if these size numbers are large, the problem occurrence, otherwise the problems does not occur.
    ImagetoSave.Width := Width;
    ImagetoSave.Height:= Height;
    Canvas.CopyRect(Rect(0,0,Image1.Width,Image1.Height),
    Image1.Picture.Bitmap.Canvas,
    Rect(0,0,Image1.Width,Image1.Height));
    SetSize(Image1.Width,Image1.Height);
    ImagetoSave.Width := Width;
    ImagetoSave.Height:= Height;
  end;
  ImagetoSave.Picture.Bitmap.SaveToFile('/home/user/Image/copycreate.bmp');
  FileListBox1.UpdateFileList;
end;
procedure TForm1.FileListBox1Change(Sender: TObject);
begin
  if FileListBox1.ItemIndex <> -1 then
  begin
    //Loading
    Image3.Picture.bitmap.TransParentColor := clGreen; //Valuable!
    Image3.Picture.bitmap.LoadFromFile(FileListBox1.FileName);
    Image3.Width := Image3.Picture.bitmap.Width;
    Image3.Height := Image3.Picture.bitmap.Height;
  end;

end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160225/d602398b/attachment.html>

Reply by email

Mattias Gaertner
to 최경식
Show quoted text 6 lines
[...] procedure TForm1.Button3Click(Sender: TObject); var ImagetoSave : TImage; begin ImagetoSave := TImage.Create(Self);

A TImage is a visual control that uses a graphic (e.g. a TBitmap) to paint.
If you only need a memory image use TBitmap directly instead.

This copies pixels (not attributes):

var
  ImagetoSave : TBitmap;
begin
  ImagetoSave := TBitmap.Create(Self);
  with ImagetoSave do
  begin
    PixelFormat := pf32bit;
    SetSize(Image1.Width,Image1.Height);
    Canvas.CopyRect(Rect(0,0,Image1.Width,Image1.Height),
    Image1.Picture.Bitmap.Canvas,
    Rect(0,0,Image1.Width,Image1.Height));
  end;
  ImagetoSave.SaveToFile('/home/user/Image/copycreate.bmp');
  FileListBox1.UpdateFileList;
end;
Show quoted text 6 lines
procedure TForm1.FileListBox1Change(Sender: TObject); begin if FileListBox1.ItemIndex &lt;&gt; -1 then begin //Loading Image3.Picture.bitmap.TransParentColor := clGreen; //Valuable!

Hint:
If you also want to copy attributes like TransparentColor, use

ImagetoSave.Assign(Image1.Picture.Bitmap);

Mattias

Reply by email

최경식
to Mattias Gaertner
Earlier message 63 lines
-----Original Message----- From: "Mattias Gaertner"&lt;&gt; To: &lt;&gt;; Cc: Sent: 2016-02-25 (?) 19:57:19 Subject: Re: [Lazarus] Image Copy and Load Fail. On Thu, 25 Feb 2016 19:28:57 +0900 (KST) ??? &lt;&gt; wrote: &gt;[...] &gt; procedure TForm1.Button3Click(Sender: TObject); &gt; var &gt; ImagetoSave : TImage; &gt; begin &gt; ImagetoSave := TImage.Create(Self); A TImage is a visual control that uses a graphic (e.g. a TBitmap) to paint. If you only need a memory image use TBitmap directly instead. This copies pixels (not attributes): var ImagetoSave : TBitmap; begin ImagetoSave := TBitmap.Create(Self); with ImagetoSave do begin PixelFormat := pf32bit; SetSize(Image1.Width,Image1.Height); Canvas.CopyRect(Rect(0,0,Image1.Width,Image1.Height), Image1.Picture.Bitmap.Canvas, Rect(0,0,Image1.Width,Image1.Height)); end; ImagetoSave.SaveToFile('/home/user/Image/copycreate.bmp'); FileListBox1.UpdateFileList; end; &gt; procedure TForm1.FileListBox1Change(Sender: TObject); &gt; begin &gt; if FileListBox1.ItemIndex &lt;&gt; -1 then &gt; begin &gt; //Loading &gt; Image3.Picture.bitmap.TransParentColor := clGreen; //Valuable! Hint: If you also want to copy attributes like TransparentColor, use ImagetoSave.Assign(Image1.Picture.Bitmap); Mattias -- Thank you. But the problem still occurs. I set the size to 4200 * 900 -&gt; copy -&gt; re-set the size. My platform is ARM-linux and OS is Lubuntu, Lazarus 1.0.10+dpkg (I tested newest version with same problem..)

Reply by email