|
-
Feb 21st, 2004, 12:48 PM
#1
Thread Starter
New Member
Whats wrong with this?
This is the error message given when i try and draw a rectangle
An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: Invalid parameter used.
I get an error from this code:
Private Sub picBoard_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picImage.MouseMove
If isDragging Then
Dim gr As Graphics = picImage.CreateGraphics
gr.Clear(picImage.BackColor)
Dim rect As New Rectangle(startX, startY, e.X - startX, e.Y - startY)
gr.DrawRectangle(Pens.Red, rect)
gr.FillRectangle(Brushes.Transparent, rect)
Dim bmpCropped As New Bitmap(e.X - startX, e.Y - startY)
Dim grBitmap As Graphics = Graphics.FromImage(bmpCropped)
grBitmap.DrawImage(picImage.Image, 0, 0, rect, _
GraphicsUnit.Pixel)
picImage.Image = bmpCropped
picImage.SizeMode = PictureBoxSizeMode.Normal
gr.Dispose()
End If
End Sub
This is supposed to crop the image from the rectangle drawn.
the error is from this line of code because it accepts invalid inputs i think.
Dim bmpCropped As New Bitmap(e.X - startX, e.Y - startY)
-
Feb 22nd, 2004, 05:53 PM
#2
Frenzied Member
Are you sure the dimensions of the bitmap you are trying to create won't become negative? Try using absolute values of e.X - startX and e.Y - startY
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Feb 23rd, 2004, 12:20 PM
#3
Thread Starter
New Member
Originally posted by Lunatic3
Are you sure the dimensions of the bitmap you are trying to create won't become negative? Try using absolute values of e.X - startX and e.Y - startY
How do i use absolute values?
-
Feb 23rd, 2004, 12:22 PM
#4
Frenzied Member
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
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
|