Click here to Skip to main content
15,505,442 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've converted an image to its RGB values with this code:

VB
Dim bmp As Bitmap = New Bitmap("C:\Users\c3301\Desktop\image.png")
      Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
      Dim bmpData As BitmapData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
      Dim ptr As IntPtr = bmpData.Scan0
      Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height
      Dim rgbValues(bytes - 1) As Byte
      Marshal.Copy(ptr, rgbValues, 0, bytes)

      ' Retrieve RGB values
      Dim RedValue As Int32
      Dim GreenValue As Int32
      Dim BlueValue As Int32
      Dim l As Integer = 0
      For x = 0 To bmp.Width - 1
          For y = 0 To bmp.Height - 1
              l = ((bmp.Width * 3 * y) + (x * 3))
              RedValue = rgbValues(l)
              GreenValue = rgbValues(l + 1)
              BlueValue = rgbValues(l + 2)
              ListBox1.Items.Add(RedValue & ", " & GreenValue & ", " & BlueValue)
         Next
      Next
      bmp.UnlockBits(bmpData)


Is there any way to convert back to an image?
Posted
Comments
Maciej Los 30-Sep-15 14:55pm    
Yeah, it's possible to convert it back.
Bitonal (TIFF) Image Converter for .NET[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900