Results 1 to 3 of 3

Thread: problem with picture selection

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    72

    Exclamation problem with picture selection

    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

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: problem with picture selection

    Quote Originally Posted by uttam
    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,

    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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: problem with picture selection

    If the figure will be a rectangle, you can do..
    VB Code:
    1. PictureBox1.Image = Image.FromFile("C:\eiffel.jpg")
    2.         Dim bm As Bitmap = New Bitmap(200, 200)
    3.         Dim gr As Graphics = Graphics.FromImage(bm)
    4.         gr.DrawImage(PictureBox1.Image, 0, 0, New RectangleF(50, 50, 200, 200), GraphicsUnit.Pixel)
    5.         'bm is the bitmap inside that coordinates, if you want to save it..
    6.         bm.Save("C:\NewImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    7.         gr.Dispose()
    8.         gr = Nothing
    But, if it will be any kind of polygon (not a rectangle), you can use a GraphicsPath to do it..
    VB Code:
    1. PictureBox1.Image = Image.FromFile("C:\eiffel.jpg") 'Load an image, here or in design mode
    2.         Dim bm As Bitmap = New Bitmap(300, 300)  'bitmap with its size
    3.         'The GraphicsPath..
    4.         Dim gp As Drawing.Drawing2D.GraphicsPath = New Drawing.Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding)
    5.         Dim pts(4) As PointF 'Array of points for the GraphicsPath
    6.         Dim gr As Graphics = Graphics.FromImage(bm)
    7.  
    8.         'Set the path coordinates (points)
    9.         pts(0).X = 10 : pts(0).Y = 10
    10.         pts(1).X = 100 : pts(1).Y = 50
    11.         pts(2).X = 140 : pts(2).Y = 250
    12.         pts(3).X = 30 : pts(3).Y = 300
    13.         pts(4).X = 10 : pts(4).Y = 10 'Back to origin to close the figure
    14.  
    15.         gp.AddLines(pts)     'Create the graphicspath drawing lines from points array
    16.         gp.CloseAllFigures() 'Ensure figures are closed if you want
    17.         gr.SetClip(gp)       'Clip the path area
    18.         gr.DrawImage(PictureBox1.Image, 0, 0) 'Draw it
    19.         bm.Save("C:\NewImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 'Save the result
    20.  
    21.         gr.Dispose()
    22.         pts = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width