Recent

Author Topic: Unwanted canvas clear  (Read 4003 times)

user5

  • Sr. Member
  • ****
  • Posts: 287
Unwanted canvas clear
« 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;

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: Unwanted canvas clear
« Reply #1 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.
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

user5

  • Sr. Member
  • ****
  • Posts: 287
Re: Unwanted canvas clear
« Reply #2 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!!!!!

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: Unwanted canvas clear
« Reply #3 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?
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

user5

  • Sr. Member
  • ****
  • Posts: 287
Re: Unwanted canvas clear
« Reply #4 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

jfmadre

  • New member
  • *
  • Posts: 7
Re: Unwanted canvas clear
« Reply #5 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 ?


user5

  • Sr. Member
  • ****
  • Posts: 287
Re: Unwanted canvas clear
« Reply #6 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