Convert RAW data to grayscale bitmap
-
I write a simple application for grabbing data from an special scanner. The data is RAW grayscale and I want to convert it to bitmap. The width and height of image is known. Is there any body can help me do this? Any suggestion, hint? Best regards, A. Riazi
-
I write a simple application for grabbing data from an special scanner. The data is RAW grayscale and I want to convert it to bitmap. The width and height of image is known. Is there any body can help me do this? Any suggestion, hint? Best regards, A. Riazi
define "RAW" Image Toolkits | Image Processing | Cleek
-
I write a simple application for grabbing data from an special scanner. The data is RAW grayscale and I want to convert it to bitmap. The width and height of image is known. Is there any body can help me do this? Any suggestion, hint? Best regards, A. Riazi
-
I write a simple application for grabbing data from an special scanner. The data is RAW grayscale and I want to convert it to bitmap. The width and height of image is known. Is there any body can help me do this? Any suggestion, hint? Best regards, A. Riazi
It depends on format of the raw data. The simpilest solution would be to write a function that reads the RAW data, one pixel at a time converting the return value to RGB. Then create a bitmap of the same size, select it into a memory DC, and copy the data to it.
// Get pixel from your raw data class
COLORREF CRawData::GetPixel(int x, int y)
{
.....
}
// Convert to bitmap
BOOL CRawData::ConvertToBitmap()
{
if( !m_pData )
return FALSE;if( m\_Bitmap.GetSafeHandle() ) m\_Bitmap.DeleteObject(). .... // creaate bitmap .... // create memory DC .... // slecect bitmap into DC if( something went wrong ) .... // clean up and return FALSE // Copy data for( int y=0; y < m\_nHeight; ++y ) { for( int x=0; x < m\_nWidth ) dcMem.Set(x,y,GetPixel(x,y)); } .... // select oldbitmap into DC return TRUE;
}
The above would be slow, but it is the simpilist way to do it. Now if you want to save it to a disk file, you should look at using GDI+ or one of the articles at codeproject on working with DIBs (bitmaps). Gool luck! Signed John R. Shaw
-
define "RAW" Image Toolkits | Image Processing | Cleek
RAW means I have pixel values. The fact is I have a grayscale image in RAW. But I have no idea of how to create a simple image that can be viewed easily with some graphics application like ACDSee. Every pixel is represented by 8 bits and the width and height of image is known. Any idea? Best regards, A. Riazi
-
It depends on format of the raw data. The simpilest solution would be to write a function that reads the RAW data, one pixel at a time converting the return value to RGB. Then create a bitmap of the same size, select it into a memory DC, and copy the data to it.
// Get pixel from your raw data class
COLORREF CRawData::GetPixel(int x, int y)
{
.....
}
// Convert to bitmap
BOOL CRawData::ConvertToBitmap()
{
if( !m_pData )
return FALSE;if( m\_Bitmap.GetSafeHandle() ) m\_Bitmap.DeleteObject(). .... // creaate bitmap .... // create memory DC .... // slecect bitmap into DC if( something went wrong ) .... // clean up and return FALSE // Copy data for( int y=0; y < m\_nHeight; ++y ) { for( int x=0; x < m\_nWidth ) dcMem.Set(x,y,GetPixel(x,y)); } .... // select oldbitmap into DC return TRUE;
}
The above would be slow, but it is the simpilist way to do it. Now if you want to save it to a disk file, you should look at using GDI+ or one of the articles at codeproject on working with DIBs (bitmaps). Gool luck! Signed John R. Shaw
Hi, Sorry that I asked you again. I have not much experience in graphics programming. The fact is I have a grayscale image in RAW. But I have no idea of how to create a simple image that can be viewed easily with some graphics application like ACDSee. Every pixel is represented by 8 bits and the width and height of image is known. This is not important for me the image file is BMP or Tiff. Any idea? Best regards, A. Riazi
-
RAW means I have pixel values. The fact is I have a grayscale image in RAW. But I have no idea of how to create a simple image that can be viewed easily with some graphics application like ACDSee. Every pixel is represented by 8 bits and the width and height of image is known. Any idea? Best regards, A. Riazi
A. Riazi wrote: Every pixel is represented by 8 bits and the width and height of image is known. so, you have 8-bit grayscale. "RAW" has a pretty specific meaning - it usually refers to the unprocessed/uncompressed data that comes directly from the scanner/digicam . it's generally in an exotic colorspace, and often the pixels are scaled logarithmically. and all of this depends on the manufacturer and model of scanner/camera - every one does it differently. if you have 8-bit grayscale, you can create a BMP file pretty easily: 1. open a file 2. write a BITMAPFILEINFO struct 3. write a BITMAPINFOHEADER struct 4. write a 256 color grayscale palette 5. write the pixel rows - in bottom-up order, with padding on the ends to ensure that each row is a multiple of 4 bytes wide Image Toolkits | Image Processing | Cleek