[Gambas-user] Coding problem
Benoit Minisini
gambas at ...1...
Fri Apr 2 22:30:17 CEST 2004
On Friday 02 April 2004 23:19, Fabien3D wrote:
> I've got a problem, maybe very simple !
>
> On VB, there were several ways to load a picture to know its dimensions :
> 1. Loading the picture in an Image control which AutoSize property set to
> True. Retrieving the dimensions of the picture was just about knowing the
> dimensions of the Image control.
>
> 2. Creating a device context (CreateObject, CreateCompatibleDC,
> SelectObject, DeleteObject), loading the picture in this device context ad
> retrieving the dimensions of the device context.
>
> In Gambas, as a newbie, things seem similar... but different. I suppose I
> have to create a class of a picture, load the image into it, and retrieve
> the dimensions. But I have some problems in loading the image in the class
> ! This is the code :
>
> ' Gambas class file
> PUBLIC SUB Main()
>
> hImage AS Picture
You should write 'hImage AS Image', because you are going to load an image in
memory. A Picture is an image stored on a X11 server. You use it only when
you want to display the image.
>
> hImage = NEW hImage
Means nothing. 'hImage = NEW Image' should be better
>
> hImage.Picture = Picture["/home/fabien/Economiseur_ecran/Panoramique
> Uluru_1.jpg"]
> hImage.Visible = TRUE
Means nothing too. Picture is not a control, you can't make it visible.
To load an image, just after having instanciated it ('hImage = NEW Image'),
do: hImage.Load("/home...")
To get the width and height, just use hImage.Width and hImage.Height
> END
>
> PUBLIC SUB Form_Open()
>
> pcbScreenSaver.Left = 0
> pcbScreenSaver.Top = 0
>
> pcbScreenSaver.Picture = hImage.Picture
> END
>
> I know the last line is wrong. But how can I get the result suggested by
> the code of this line ?
But the last line is the only one that is right :-)
Note that the real way to get the dimensions of a image stored in a file is:
reading them directly in it! But, of course, it depends on the file format,
and as QT does not allow such a thing, even if it would be easy for
Trolltech, I should write it myself.
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list