Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert RAW data to grayscale bitmap

Convert RAW data to grayscale bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abbas_Riazi
    wrote on last edited by
    #1

    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

    C S J 3 Replies Last reply
    0
    • A Abbas_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

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      define "RAW" Image Toolkits | Image Processing | Cleek

      A 1 Reply Last reply
      0
      • A Abbas_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

        S Offline
        S Offline
        Shog9 0
        wrote on last edited by
        #3

        CreateBitmap() Read the MSDN writeup before you mess with it. Pay special attention to the alignment notes - you may have to massage your data a bit first. Medication for us all You think you know me, well you're wrong

        1 Reply Last reply
        0
        • A Abbas_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

          J Offline
          J Offline
          John Shaw
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • C Chris Losinger

            define "RAW" Image Toolkits | Image Processing | Cleek

            A Offline
            A Offline
            Abbas_Riazi
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • J John Shaw

              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

              A Offline
              A Offline
              Abbas_Riazi
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • A Abbas_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

                C Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups