Dear expert,
I have a problem with picturebox in vb.net.Actually I need to take 4 co-ordinates and depnding on that co-ordinate we need to copy that part of an image to somewhere else.So please help me.
Thanks in advance.
Uttam
Printable View
Dear expert,
I have a problem with picturebox in vb.net.Actually I need to take 4 co-ordinates and depnding on that co-ordinate we need to copy that part of an image to somewhere else.So please help me.
Thanks in advance.
Uttam
Hi,Quote:
Originally Posted by uttam
After an MSDN search found some links about pictures:
http://msdn.microsoft.com/library/de.../selection.asp
http://msdn.microsoft.com/library/de...inkpicture.asp
Hope it helps,
sparrow1
If the figure will be a rectangle, you can do..
But, if it will be any kind of polygon (not a rectangle), you can use a GraphicsPath to do it..VB Code:
PictureBox1.Image = Image.FromFile("C:\eiffel.jpg") Dim bm As Bitmap = New Bitmap(200, 200) Dim gr As Graphics = Graphics.FromImage(bm) gr.DrawImage(PictureBox1.Image, 0, 0, New RectangleF(50, 50, 200, 200), GraphicsUnit.Pixel) 'bm is the bitmap inside that coordinates, if you want to save it.. bm.Save("C:\NewImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) gr.Dispose() gr = Nothing
VB Code:
PictureBox1.Image = Image.FromFile("C:\eiffel.jpg") 'Load an image, here or in design mode Dim bm As Bitmap = New Bitmap(300, 300) 'bitmap with its size 'The GraphicsPath.. Dim gp As Drawing.Drawing2D.GraphicsPath = New Drawing.Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding) Dim pts(4) As PointF 'Array of points for the GraphicsPath Dim gr As Graphics = Graphics.FromImage(bm) 'Set the path coordinates (points) pts(0).X = 10 : pts(0).Y = 10 pts(1).X = 100 : pts(1).Y = 50 pts(2).X = 140 : pts(2).Y = 250 pts(3).X = 30 : pts(3).Y = 300 pts(4).X = 10 : pts(4).Y = 10 'Back to origin to close the figure gp.AddLines(pts) 'Create the graphicspath drawing lines from points array gp.CloseAllFigures() 'Ensure figures are closed if you want gr.SetClip(gp) 'Clip the path area gr.DrawImage(PictureBox1.Image, 0, 0) 'Draw it bm.Save("C:\NewImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 'Save the result gr.Dispose() pts = Nothing