[Gambas-devel] Transparent DrawingArea

Fabien Bodard gambas.fr at ...176...
Tue Dec 20 10:05:37 CET 2016


You cant drawing in a DrawingArea outside the draw event. Gambas use
ascynchronous drawing. (You can nevertheless set the cache mode to
true)


But prefer this :
Private $hImage as Image
 Public Sub btnImage_Click()
    Dialog.Path = "/ home / gambas / projects / images"
    Dialog.Filter = ["Image files (* .jpg; * .jpeg; * .png; * .bmp)", "All
files (*. *)"]
    If Dialog.OpenFile() Then Return
    $hImage = New Image
    $hImage.Load(Dialog.Path)
    dwgImage.Resize(hImage.Width, hImage.Height)

    dwgImage.Refresh
    Catch
    Message.Warning(Error.Text & "!")
End

Public Sub dwgImage_Draw()


    Draw.Fillcolor = Color.Gray
    Draw.FillStyle = Fill.Solid
    Draw.Rect(0, 0, $hImage.Width, $hImage.Height)
    Draw.Image($hImage, 0, 0)
    Draw.End


 End


Nota: The Draw Class is Deprecated, prefer the use of the Paint Class
for drawing. Paint is vector based and is far more powerfull. (and the
current Draw class is based on the paint one)


The _Draw Sub with the _Data sub of the grid view is one of the
fabulous things of gambas. But it take a little bit of cerebral
training, because thinking in term of separate Data / Viewer is not
natural. But so powerfull.



2016-12-19 22:24 GMT+01:00 RichardB <deep_sky at ...761...>:
> Thanks for the advice - much appreciated.  But I'm still having problems.
>
> I tried a simple test by creating a form with just a single button
> (btnImage) and a DrawingArea (dwgImage) on it.  I added the following code
> to the button's click function:
>
>    Public Sub btnImage_Click()
>     Dim hImage As Image
>     Dialog.Path = "/ home / gambas / projects / images"
>     Dialog.Filter = ["Image files (* .jpg; * .jpeg; * .png; * .bmp)", "All
> files (*. *)"]
>     If Dialog.OpenFile() Then Return
>     hImage = New Image
>     hImage.Load(Dialog.Path)
>     dwgImage.Resize(hImage.Width, hImage.Height)
>     dwgImage.Clear()
>     Draw.Begin(dwgImage)
>     Draw.Fillcolor = Color.Gray
>     Draw.FillStyle = Fill.Solid
>     Draw.Rect(0, 0, hImage.Width, hImage.Height)
>     Draw.Image(hImage, 0, 0)
>     Draw.End
>     dwgImage.Visible = True
>     Catch
>     Message.Warning(Error.Text & "!")
>    End
>
> When run, the dialog opens fine, I select the image ok...but it fails on the
> "Draw.Begin(dwgImage) " line, with the error "Cannot paint outside of draw
> event handler".  I can't see where I've made an error.
>
> Thanks again for your help.
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.com/Transparent-DrawingArea-tp58023p58033.html
> Sent from the gambas-devel mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today.http://sdm.link/intel
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel



-- 
Fabien Bodard




More information about the Devel mailing list