[Gambas-user] Paint an image

Tobias Boege taboege at ...626...
Sun Nov 24 16:01:34 CET 2013


On Sun, 24 Nov 2013, ukimiku wrote:
> Hi Fabien,
> 
> thank you for your prompt reply. I must be missing something, I guess. It
> still does not display the image.
> 
> In the Form_open event, I set
>    fr.cached = false
> 
> I see the effect when I drag the window with the mouse. It is slow and a bit
> jerky as, I guess, the redrawing is taking place quite often.
> 
> Still, the image does not appear. I have checked that the pixel values
> contain reasonable color components, but not a single pixel of "img" is
> being painted.
> 
> So far, my dr.Draw() event reads like this:
> Public Sub fr_Draw()
>   Paint.Begin(fr)
>   fr.Background = Color.RGB(100, 140, 180)
>   Paint.Image(img, 0, 0)
>   paint.End
> End
> 
> What am I missing? Is "Paint.Image" the right command?
> 
> Thank you.
> 

Oops. I should have seen this earlier... Your suspicion is justified.
Paint.Image() only creates a brush from the image. I think you can imagine
this brush as a "stamp" of your image. You can then paint and fill a
rectangle or something to see your picture like:

Public Sub fr_Draw()
  Paint.Brush = Paint.Image(img)
  Paint.Rectangle(0, 0, img.W, img.H)
  Paint.Fill()
End

but things get complicated if you want the image to be painted on
coordinates which are non-multiples of img.W and img.H - you may try it out!

The easier and more flexible method of painting a standalone image (not an
image pattern which is what Paint.Image() seems to be there for) is
Paint.DrawImage():

Public Sub fr_Draw()
  Paint.DrawImage(img, 0, 0)
End

You can safely vary the coordinates with this method and immediately see the
Image.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list