Quantcast

Transparent DrawingArea

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Transparent DrawingArea

RichardB
I’m trying to develop an app in Gambas v3.9.1 that uses a transparent DrawingArea layered over a PictureBox – the intention is to load a picture into the PictureBox and mark points (or lines) on the DrawingArea for measurement. I’m a newbie to Gambas – does anyone have any advice on how to get this to work?  Or is there a better way to do this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

Moviga Technologies
You can draw the image in the DrawingArea, and then draw on top of it.


Den 16. des. 2016 00:46, skrev RichardB:

> I’m trying to develop an app in Gambas v3.9.1 that uses a transparent
> DrawingArea layered over a PictureBox – the intention is to load a picture
> into the PictureBox and mark points (or lines) on the DrawingArea for
> measurement. I’m a newbie to Gambas – does anyone have any advice on how to
> get this to work?  Or is there a better way to do this?
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.com/Transparent-DrawingArea-tp58023.html
> Sent from the gambas-devel mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-devel


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

Fabien Bodard-4
Maybe you can share your code so we can drive you in the good way. And
say us what is your goal.

2016-12-16 9:28 GMT+01:00 Moviga Technologies <[hidden email]>:

> You can draw the image in the DrawingArea, and then draw on top of it.
>
>
> Den 16. des. 2016 00:46, skrev RichardB:
>> I’m trying to develop an app in Gambas v3.9.1 that uses a transparent
>> DrawingArea layered over a PictureBox – the intention is to load a picture
>> into the PictureBox and mark points (or lines) on the DrawingArea for
>> measurement. I’m a newbie to Gambas – does anyone have any advice on how to
>> get this to work?  Or is there a better way to do this?
>>
>>
>>
>> --
>> View this message in context: http://gambas.8142.n7.nabble.com/Transparent-DrawingArea-tp58023.html
>> Sent from the gambas-devel mailing list archive at Nabble.com.
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Gambas-devel mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-devel
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-devel



--
Fabien Bodard

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

RichardB
In reply to this post by Moviga Technologies
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

Fabien Bodard-4
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 <[hidden email]>:

> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-devel



--
Fabien Bodard

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

RichardB
Hi Fabien:

Thanks for your advice.  Still having problems.
I've changed my code to what you gave me:


 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.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
 End

Public Sub btnDraw_Click()
  dwgImage_Draw
End


Running the code will allow me to open the dialog and select a jpg.  Stopping the code after executing the "$hImage.Load(Dialog.Path)" line shows me that the value of Pixels for $hImage is "Out of bounds" and that the height and width are both 0, so something is causing the image load to fail.  The Dialog.Path is correct, showing the correct path and filename.  The Cached property for dwgImage is True.  What am I missing?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

Fabien Bodard-4
Ok Richard this is a working  exemple  just for you.

Fill free to query us about all you want.

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel

DemoToRiChardB-0.0.1.tar.gz (16K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Transparent DrawingArea

RichardB
Thanks Fabien!  That's precisely what I was looking for.
Loading...