Results 1 to 4 of 4

Thread: Image Manipulation in Vb.nET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Westminster, Md.
    Posts
    163

    Image Manipulation in Vb.nET

    I have a picture box loaded with an image.

    I want to take part of that image say a 20 square pixel region to y+10 and copy that into an Image object ( so I can do stuff with it).

    Then I want to take that and overlay it on another image, and be able to move it around and stuff.


    Unfortunately I have no idea how to even start in VB.NET.

    How do I chop out the part of the image that I want?

    Eiredrake

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    the graphic things in vb.net is in the system.drawing and system.drawing.drawing2d namespaces(gdi+)

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    www.c-sharpcorner.com
    That site is C# oriented, but they have a graphics section that has a lot of sample code. Most of the graphics stuff will be the same in C# and VB.Net.

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Image Manipulation in Vb.nET

    Originally posted by Eiredrake
    I have a picture box loaded with an image.

    I want to take part of that image say a 20 square pixel region to y+10 and copy that into an Image object ( so I can do stuff with it).

    Then I want to take that and overlay it on another image, and be able to move it around and stuff.


    Unfortunately I have no idea how to even start in VB.NET.

    How do I chop out the part of the image that I want?

    Eiredrake
    I dont know what you mean by overlay...but to take out a part of it and copy it to a variable... here's a sample code I wrote:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ' The cut-out portion will be 20 by 20 pixels
    3.         Dim cutWidth As Integer = 20
    4.         Dim cutHeight As Integer = 20
    5.  
    6.         ' Portion of the original image that is going to be cut out
    7.         Dim srcRect As New Rectangle(50, 50, cutWidth, cutheight)
    8.         Dim destRect As New Rectangle(0, 0, cutWidth, cutHeight)
    9.         ' Saves the part of the image what will be cut out
    10.         Dim bmpSelection As New Bitmap(cutWidth, cutHeight)
    11.         Dim gr As Graphics = Graphics.FromImage(bmpSelection)
    12.         ' The rectangle represents the part of the picture that you want to cut out
    13.  
    14.         gr.DrawImage(picSrc.Image, destRect, srcRect, GraphicsUnit.Pixel)
    15.         ' bmpSelection contains the cutout now...
    16.  
    17.  
    18.         ' Do this if you want to replace the cutout with a blank rectangle
    19.         Dim myBrush As New SolidBrush(picSrc.BackColor)
    20.         gr = Graphics.FromImage(picSrc.Image)
    21.         gr.FillRectangle(myBrush, srcRect)
    22.         picSrc.Invalidate(srcRect)
    23.  
    24.  
    25.         gr.Dispose()
    26.  
    27.         picTest.Image = bmpSelection
    28.     End Sub

    make a windows app project and put two picboxes in it with a button. Name a picturebox "picSrc" and put the original image in it. Rename the other picturebox to "picTest"
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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