Results 1 to 12 of 12

Thread: Bitmaps into arrays

  1. #1

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Exclamation Bitmaps into arrays

    Argh! It always comes to this when I'm working with images. Usually, when I need to programatically interpret data in a bitmap, I do it graphically, using GetPixel in a PictureBox. But that's slow and inefficient.
    How can I load each pixel of a bitmap into a 2-dimensional array? Say the bitmap is 10 pixels by 10 pixels: the array would be Bitmap(10,10).
    Each item in the array would contain a long value indicating the color at that location in the file.
    Can someone help me with this?

    Thanks!
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: Bitmaps into arrays

    Here's what you're looking for...

    It should explain everything you need to know about bitmap images on a raw binary level...
    It's just basic theory, but you can adapt the code to basically anything bitmap related...

    Hope this helps... enjoy...
    Attached Files Attached Files
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  3. #3

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Bitmaps into arrays

    Thank you, I'll take a look.
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  4. #4

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Bitmaps into arrays

    I keep getting a 'Subscript out of Range' error...
    I haven't tried to understand the code yet, but what exactly does it do? Does it open an existing bitmap and interprets it or does it create a bitmap file?
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  5. #5
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: Bitmaps into arrays

    Basically what the program does is convert a bitmap into 24bit depth...

    The reason I gave you the file (even tho it's irreleveant) is that it loads the bits for the bitmap directly from the file i.e. it stores the pixel location and the colour of the pixel directly into the array, without having to open the image and do a pixel scan....

    That way it's much faster...

    As for the error, I'll check it out and get back to you...
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  6. #6

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Bitmaps into arrays

    Alright, thanks. (There's an invalid label, too, but all you have to do is change "ErrHandler" to "ErrHandle" in the GoTo statement).
    Now what is 24bit depth? Well, obviously, 24 bits of color but -- argh, I'm confused. I did some research, but it didn't help...
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  7. #7
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: Bitmaps into arrays

    lol...
    Don't worry about the conversion...

    Just take a look at the part where the data is loaded into the arrays....

    After a while at staring at it it begins to make sense...
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  8. #8

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Bitmaps into arrays

    Alright... I will. Thanks
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  9. #9

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Bitmaps into arrays

    Hmm, actually...
    Doesn't VB have any built-in function (or API) for getting the RGB values for each pixel in a BMP?
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  10. #10
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: Bitmaps into arrays

    Yes, but you still have to load the picture onto a device context...
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  11. #11
    Junior Member
    Join Date
    Dec 2005
    Posts
    19

    Re: Bitmaps into arrays

    i don't know whether this can help yo.
    I was working on steganography and had similar problems to get the RGB values from a pixel.

    After searching i got this code from the net. Check if this helps!!!!

    --------------------------------------------------------------------------
    'GET RED COMPONENT

    Public Function GetRedValue(ByVal Color As Long) As Byte
    GetRedValue = CByte(Color And &HFF)
    End Function

    --------------------------------------------------------------------------


    'GET GREEN COMPONENT



    Public Function GetGreenValue(ByVal Color As Long) As Byte
    GetGreenValue = CByte((Color And 65280) \ 256)
    End Function

    --------------------------------------------------------------------------
    'GET BLUE COMPONENT

    Public Function GetBlueValue(ByVal Color As Long) As Byte
    GetBlueValue = CByte((Color And &HFF0000) \ 65536)
    End Function

    The color arguement is the colour of the current pixel that you get from the GetPixel method of "gdi32" library...

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Bitmaps into arrays

    I would create a table on the fly, and then convert the unique colors in the table. You'd still have to loop thru all pixels, though.

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