Draw shapes on images

Example requests & Code samples for GdPicture Toolkits.
Post Reply
Loopy
Posts: 6
Joined: Wed Jun 04, 2008 6:49 am

Draw shapes on images

Post by Loopy » Mon Jul 21, 2008 9: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.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Draw shapes on images

Post by Loïc » Tue Jul 22, 2008 10: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): https://www.gdpicture.com/guides/gdpicture

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

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

Re: Draw shapes on images

Post by Loopy » Tue Jul 22, 2008 11:21 am

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

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Draw shapes on images

Post by Loïc » Tue Jul 22, 2008 4: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:

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

Best regards,

Loïc Carrère

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

Re: Draw shapes on images

Post by Loopy » Tue Jul 22, 2008 9: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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest