Results 1 to 7 of 7

Thread: Reading each pixel from an image

  1. #1
    Join Date
    Jul 2006
    Posts
    276
    Rep Power
    0

    Default Reading each pixel from an image

    Is there a way to open an image and read each pixel value in vb.net?
    The greatest discovery of all men through lifetime is that a man can alter his life by altering his attitude!

  2. #2
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by norminator View Post
    Is there a way to open an image and read each pixel value in vb.net?
    I need more info on what you are trying to acheive. post a sample code or something.

    However the code below shows how you can read pixel values of an image on a form with a picturebox named picImage

    Code:
        Dim clr As Integer
        Dim xmax As Integer
        Dim ymax As Integer
        Dim x As Integer
        Dim y As Integer
    
     ' Get the bitmap and its dimensions.
        Dim bm As Bitmap = picImage.Image
        xmax = bm.Width - 1
        ymax = bm.Height - 1
    
        ' read the pixels 
        For y = 0 To ymax
            For x = 0 To xmax
                With bm.GetPixel(x, y)
                    clr =  .R &  .G &  .B
                    console.writeline(.R)
                    console.writeline(.G)
                    console.writeline(.B)
                    console.writeline(clr)
                End With
            Next x
        Next y
    you can use the .R,.G and the .B individually or as an RGB Group to form a color

    You can further read the properties of the pixel using the .operator (dot operator)
    Example: bm.GetPixel(x, y).GetBrightness


    To read the pixels straight from a file use:
    Code:
    Dim picFile as string= "C:\somepath\somepic.jpg"
    Dim bm As Bitmap As New Bitmap(picFile) 'this will replace Dim bm As Bitmap = picImage.Image
    To manipulate the pixels use the SetPixel method
    Last edited by ToxXxic; Oct 7, 2009 at 03:47 PM.
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  3. #3
    Join Date
    Jul 2006
    Posts
    276
    Rep Power
    0

    Default

    ok i am going to try that code parry...

    umm what about reading the values of a .img file (iso file)..do you have any idea on how to conduct this..I have done it using binary reader..is that the right way to use it so far it looks good?
    The greatest discovery of all men through lifetime is that a man can alter his life by altering his attitude!

  4. #4
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    sounds like 2 different things to me:
    1. Graphics - Image (jpg, png, gif, etc)
    2. CD/DVD - Image (iso, img, bin, etc)
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  5. #5
    Join Date
    Jul 2006
    Posts
    276
    Rep Power
    0

    Default

    Quote Originally Posted by ToxXxic View Post
    I need more info on what you are trying to acheive. post a sample code or something.

    However the code below shows how you can read pixel values of an image on a form with a picturebox named picImage

    clipped for brevity
    The code you provided returned an error arithmetic operation resulted in an overflow.

    Trying to figure out why was debugging it dont see the reason..

    Quote Originally Posted by icymint3 View Post
    sounds like 2 different things to me:
    1. Graphics - Image (jpg, png, gif, etc)
    2. CD/DVD - Image (iso, img, bin, etc)
    I am doing both: the 2. CD/DVD - Image (iso, img, bin, etc) I did that using binary readers code ran perfectly.

    But for graphics i am getting an arithmetic overflow error
    Last edited by Arch_Angel; Oct 7, 2009 at 02:34 AM. Reason: merged multiple posts
    The greatest discovery of all men through lifetime is that a man can alter his life by altering his attitude!

  6. #6
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by norminator View Post
    The code you provided returned an error arithmetic operation resulted in an overflow.

    Trying to figure out why was debugging it dont see the reason..
    Which line is the error?
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  7. #7
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by norminator View Post
    The code you provided returned an error arithmetic operation resulted in an overflow.

    Trying to figure out why was debugging it dont see the reason..




    But for graphics i am getting an arithmetic overflow error

    change clr = .R + .G + .B to clr = .R & .G & .B
    Last edited by ToxXxic; Oct 7, 2009 at 03:52 PM.
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

Posting Permissions

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