Home | About us | Overview | Softwares - Downloads | Evaluate | Order | Support | old forums | Contact | F.A.Q. | Documentations | Search | Sitemap

Draw shapes on images

Example requests & Code samples for GdPicture ActiveX.

Draw shapes on images

Postby Loopy on Mon Jul 21, 2008 10:55 pm

Hi there!

Is it possible to draw shapes on images?
I tried several ways with GDPicturePro Demo in VB2005, but did not succeed.
This is very necessary to me, if you can give me a good example (preferred in VB2005) i will buy a license.

I hope you can help me.
Loopy
 
Posts: 6
Joined: Wed Jun 04, 2008 7:49 am

Re: Draw shapes on images

Postby Loïc on Tue Jul 22, 2008 11:28 am

Hi,

I give you a basic way to draw 1 line and 1 rectangle on an image.

For other shapes you can get a look on the online reference guide (see Draw shapes chapter): http://www.guides.gdpicture.com


Code: Select all
Imaging1.CreateImageFromFile ("input.jpg")

'Draws a Semi transparent Red line using 2 pixels pen size from (0,0) to (200,200) on the native image
Call Imaging1.DrawLine(0, 0, 200, 200, 2, Imaging1.argb(125, 255, 0, 0), True)

'Draws a Semi transparent Green rectangle using 2 pixels pen size from (0,0) to (200,200) on the native image
Call Imaging1.DrawRectangle(0, 0, 200, 200, 2, Imaging1.argb(125, 0, 255, 0), True)

Imaging1.SaveAsJPEG ("output.jpg")


Best regards,

Loïc
User avatar
Loïc
Site Admin
 
Posts: 1195
Joined: Tue Oct 17, 2006 11:48 pm
Location: France

Re: Draw shapes on images

Postby Loopy on Tue Jul 22, 2008 12:21 pm

Is it possible to draw shapes on an image by the interactive way?
I mean something like Paint from WinXP. You can open an image and draw shapes on it directly with your cursor,
you know?

Best regards,
Loopy
Loopy
 
Posts: 6
Joined: Wed Jun 04, 2008 7:49 am

Re: Draw shapes on images

Postby Loïc on Tue Jul 22, 2008 5:01 pm

Hi,

You can do that using both GdViewer & Imaging classes.

The idea is:

- Load or create an empty image into an Imaging object
- Set the loaded image into the GdViewer object

Code: Select all
GdViewer1.SetNativeImage(Imaging1.GetNativeImage)

- Catch mouse events from the GdViewer to see when the used clicked and when he moved the mouse
- Using the Imaging object, draw the desired shape using coordinates raised by the events of the GdViewer object
- Refresh the viewer -> see Redraw() method

I've uploaded a vb.net freehand drawing sample which use this technic:

http://www.gdpicture.com/support/dotnetFreehand.zip

Best regards,

Loïc Carrère
User avatar
Loïc
Site Admin
 
Posts: 1195
Joined: Tue Oct 17, 2006 11:48 pm
Location: France

Re: Draw shapes on images

Postby Loopy on Tue Jul 22, 2008 10:08 pm

Hi Loic!

Thanks for your quick response!
I've made a sample for vb2005 working fine with bitmaps.

Code: Select all
Public Class Form1

    Private p As Point

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.Imaging1.SetLicenseNumber("XXXXXX")
        Me.GdViewer1.SetLicenseNumber("XXXXXX")
        Me.GdViewer1.SetZoomFitControl()
        Me.GdViewer1.ViewerQualityAuto = False
        Me.GdViewer1.MouseMode = GdPicturePro5.ViewerMouseMode.MouseModeDefault
        Me.GdViewer1.ViewerQuality = GdPicturePro5.ViewerQuality.ViewerQualityBilinear
        Me.Imaging1.CreateImageFromFile("c:\test.bmp")
        Me.Imaging1.ConvertTo24BppRGB()
        Me.GdViewer1.SetNativeImage(Me.Imaging1.GetNativeImage)

    End Sub

    Private Sub GdViewer1_MouseDownControl1(ByVal sender As Object, ByVal e As AxGdPicturePro5.__GdViewer_MouseDownControlEvent) Handles GdViewer1.MouseDownControl

        p.X = GdViewer1.GetMouseX
        p.Y = GdViewer1.GetMouseY

    End Sub

    Private Sub GdViewer1_MouseMoveControl1(ByVal sender As Object, ByVal e As AxGdPicturePro5.__GdViewer_MouseMoveControlEvent) Handles GdViewer1.MouseMoveControl
        If e.button = 1 Then

            p.X = GdViewer1.GetMouseX
            p.Y = GdViewer1.GetMouseY

            Me.Imaging1.DrawFillEllipse(p.X - 15, p.Y - 15, 30, 30, GdPicturePro5.Colors.Aquamarine, True)
            Me.GdViewer1.Redraw()

        End If
    End Sub
End Class


You just need a Form with a GDViewer and a GDImaging on it.

Best regards,
Loopy
Loopy
 
Posts: 6
Joined: Wed Jun 04, 2008 7:49 am


Return to Example requests & Code samples

Who is online

Users browsing this forum: No registered users and 0 guests