Click here to Skip to main content
15,877,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Our program convert WEBP image format to rgb byte array image without header. and I wanna show these bytes in picture box by convert this byte array to bitmap image format..
how can I do this ?
My image is color image in format24bpprgb format...

1 solution

Since you have no header information, you have to know the dimensions of your source bitmap and create a matching bitmap, then you lock the bits and copy the raw bytes according to the format of your input image. The following snippet should get you on the way:
The sourceBitmap "class" is a meta-container, you have to obtain your information from your source knowledge.
Bitmap myBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format24bppRgb);

BitmapData myData = myBitmap.LockBits(sourceBitmap.Dimensions, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

int sStride = sourceBitmap.Stride;
int dStride = myData.Stride;

// copy the RGB bits from your raw source bitmap to the buffer of 
// myBitmap, myData.Scan0 is the first byte of the target buffer.
  byte* src = <your pointer="" to="" the="" raw="" data="">;
  byte* dst = (byte*)myData.Scan0.ToPointer();
  byte* s;
  byte* d;
  for(int row = 0; row < sourceBitmap.Height; row++)
    for(int col = 0; col < sourceBitmap.Width; col++)
       s = src + row * sStride + col * 3; //24bpp, 3 bytes per pixel
       d = dst + row * dStride + col * 3; //24bpp, 3 bytes per pixel
       d[0] = s[0];
       d[1] = s[1];
       d[2] = s[2];


Now you can display the image using myBitmap.
Share this answer

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