|
-
Jun 1st, 2006, 06:10 PM
#1
Thread Starter
Junior Member
How to draw on an image? [2005]
I'm trying to draw a dot onto an image.
I can do it is asp.NET but nothing is happening when I do the following as part of a Windows Application. An better example would be great.
Any suggestion please?
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Public Class DrawImagewithDot
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objBitmap As New Bitmap("C:\myIMG.bmp")
Dim g As Graphics = Graphics.FromImage(objBitmap)
Dim redBrush As New SolidBrush(Color.Red)
Dim blueBrush As New SolidBrush(Color.Blue)
g.FillEllipse(blueBrush, 100, 206, 10, 10)
g.FillEllipse(redBrush, 200, 180, 10, 10)
g.DrawImage(objBitmap, 10, 10)
End Sub
End Class
-
Jun 1st, 2006, 06:36 PM
#2
Re: How to draw on an image? [2005]
I'm no GDI+ guru but that code appears to be creating a Bitmap object from a file, then drawing on that Bitmap, then drawing that Bitmap on itself, then discarding the Bitmap. You aren't displaying the Bitmap anywhere in that code, although that may only be illustrative and not what you're actually doing. I'm confused by this part though:
VB Code:
g.DrawImage(objBitmap, 10, 10)
g is a Graphics object that will draw on your Bitmap, and you're telling it to draw that same Bitmap, so basically you're drawing the Bitmap on itself. Is that what you intended to do, or am I interpreting that code incorrectly?
-
Jun 1st, 2006, 06:44 PM
#3
Member
Re: How to draw on an image? [2005]
It looks to me as if you are drawing a bitmap over the dot you are drawing. Draw the bitmap onto the canvas, and then draw the dot.
VB Code:
g.FillEllipse(blueBrush, 100, 206, 10, 10)
g.FillEllipse(redBrush, 200, 180, 10, 10)
g.DrawImage(objBitmap, 10, 10)
Change to:
VB Code:
g.DrawImage(objBitmap, 10, 10)
g.FillEllipse(blueBrush, 100, 206, 10, 10)
g.FillEllipse(redBrush, 200, 180, 10, 10)
I will take a look at my GDI app and see what is happening if that isn't the problem.
-
Jun 1st, 2006, 07:25 PM
#4
Thread Starter
Junior Member
Re: How to draw on an image? [2005]
I've solved it.
Somewhere I read that only .bmp's would be correct but this doesn't seem to be the issue here.
Anyway..... this works and I'm happy!
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
Dim g As Graphics = Me.CreateGraphics()
g.Clear(Me.BackColor)
' Draw an image
Dim curImage As Image = Image.FromFile("c:/myIMG.jpg")
g.DrawImage(curImage, 0, 0, curImage.Width, curImage.Height)
Dim redBrush As New SolidBrush(Color.Red)
Dim blueBrush As New SolidBrush(Color.Blue)
g.FillEllipse(blueBrush, 100, 206, 10, 10)
g.FillEllipse(redBrush, 200, 180, 10, 10)
g.Dispose()
End Sub 'OnPaint
-
Jun 1st, 2006, 07:31 PM
#5
Thread Starter
Junior Member
Re: How to draw on an image? [2005]
Sorry jmcilhinney and Brant. I was so excited to answer my own question that I didn't see that you'd already responded. Thanks so much.
You will have gathered I'm pretty ignorant about how everything hangs together wrt graphics.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|