Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: user5 on April 04, 2014, 07:07:28 pm

Title: Unwanted canvas clear
Post by: user5 on April 04, 2014, 07:07:28 pm
I want to load a bitmap into my form on activation w/o the user having to press a button. The following loads the bitmap ok but then it disappears when the procedure ends. Any suggestions?

procedure TForm1.FormActivate();
begin
 MyBitmap := TBitmap.Create;
 MyBitmap.LoadFromFile('c:\temp7\etc');
 Canvas.Draw(0,0,MyBitmap);
 delay(2000);
end;
Title: Re: Unwanted canvas clear
Post by: Blaazen on April 04, 2014, 07:21:00 pm
Hi,

at first, do not paint anything in OnActivate. Some widgetsets does not support it at all (Qt, Carbon). Even if you have widgetset which enables you to paint out of OnPaint method (Windows or GTK2) the picture will stay there to the next Invalidate only. If you want it there permanently, there are at least three ways: use TPaintBox + OnPaint event or TImage, or move the code to Form1.OnPaint event.
Title: Re: Unwanted canvas clear
Post by: user5 on April 04, 2014, 09:54:48 pm
Thank you so much Blaazen! OnPaint worked out fine but I was wondering how to send a bitmap to a TImage. I searched previous posts and found the following but it didn't work:
    image1.Picture.Bitmap.LoadFromFile('c:\temp7\title1.bmp');

Can you tell me how to get MyBitmap into image1? (image1:TImage)

Thanx again. This is a great forum!!!!!
Title: Re: Unwanted canvas clear
Post by: Blaazen on April 04, 2014, 10:15:57 pm
It works here. I tried both:
Code: [Select]
Image1.Picture.LoadFromFile('/media/disk/v1/Lazarus_Qt/lazarus/images/LazarusForm.bmp');
and
Image1.Picture.Bitmap.LoadFromFile('/media/disk/v1/Lazarus_Qt/lazarus/images/LazarusForm.bmp');

So I can only guess - some unsupported format of your image? Or typo in filename?
Title: Re: Unwanted canvas clear
Post by: user5 on April 05, 2014, 12:03:22 pm
Sorry I didn't reply sooner; I was tired.

I can't get either procedure to work. It compiles ok but when I run it I get an error message and an assembler window.

This has happened to me before if I didn't have the correct headers/tpus in the 'uses' section. Do you know what header applies to "Picture" in Image.Picture.LoadFromFile? Bitmap and
LoadFromFile already work for me when I'm working strictly with bitmaps. Thanks
Title: Re: Unwanted canvas clear
Post by: jfmadre on April 05, 2014, 01:07:08 pm
I've tried a simple program with a Timage and a button
procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.LoadFromFile('imagefond.jpg');
end;
imagefond.jpg is in the directory of my program

when i click on the button, the image loads without problem.

I had a similar problem whith a software whith opening of assembler windows.
It occured after my software was trying to read a table over the dimension declared in a try/finally zone of my soft. The error occured then in another part of the program and that sems odd.
Solution to find this problem configure the Compiler (Project/Project options/Compiler options/ and what in french is "Infos de d├ębogage" then check the options "Intervalle (-Cr)" and "D├ębordement (-Co)"
Then when runing the soft it stops where the true error is.
Perhaps the same problem ?

Title: Re: Unwanted canvas clear
Post by: user5 on April 06, 2014, 09:31:16 am
My bonehead problem is solved. I didn't have a TImage box in my form to represent image1 and that's why it wouldn't work right. It works fine now. Thanks to you all for trying to help me. By the way, please spare a glance at my new posting titled "Bitmap wavefore from .wav file." I could really use some help there.
TinyPortal © 2005-2018