Click here to Skip to main content
16,007,504 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
Nishad S7-Nov-08 3:19
Nishad S7-Nov-08 3:19 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
Saurabh.Garg7-Nov-08 4:26
Saurabh.Garg7-Nov-08 4:26 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
Nishad S7-Nov-08 23:06
Nishad S7-Nov-08 23:06 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
aa_zz9-Nov-08 15:37
aa_zz9-Nov-08 15:37 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
aa_zz9-Nov-08 19:48
aa_zz9-Nov-08 19:48 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
Nishad S9-Nov-08 20:35
Nishad S9-Nov-08 20:35 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
aa_zz10-Nov-08 14:07
aa_zz10-Nov-08 14:07 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
Nishad S10-Nov-08 19:29
Nishad S10-Nov-08 19:29 
Well... the following is a general purpose code that read bitmap data. It was done some years back but you can refer this to modify your code for 8 bit images.

Hope this is useful.


void CBMPDlg::OnShowStructData() 
{
    // Show open dialog
    CFileDialog dlg( TRUE, "bmp", 0, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, "BMP Files (*.bmp)|*.bmp|", this );
    if( IDCANCEL == dlg.DoModal())
    {
        return;
    }

    // Get the file name
    CString   csData = dlg.GetPathName();

    // Open the file
    CFile file( csData, CFile::modeRead );
    
    // Get the structural details
    csData += "\r\n\r\nStructural Data\r\n";

    // Read BITMAPFILEHEADER
    BITMAPFILEHEADER stBFH = { 0 };
    file.Read( &stBFH, sizeof( stBFH ));

    // Convert to string
    CString csStr;
    csData += "\r\nBITMAPFILEHEADER\r\n";
    csStr.Format( "bfType          - %c%c\r\n", stBFH.bfType & 0xFF, ( stBFH.bfType >> 8 ) & 0xFF );
    csData += csStr;
    csStr.Format( "bfSize          - %lu\r\n", stBFH.bfSize );
    csData += csStr;
    csStr.Format( "bfReserved1     - %u\r\n", stBFH.bfReserved1 );
    csData += csStr;
    csStr.Format( "bfReserved1     - %u\r\n", stBFH.bfReserved1 );
    csData += csStr;
    csStr.Format( "bfOffBits       - %u\r\n", stBFH.bfOffBits );
    csData += csStr;

    // Read BITMAPINFOHEADER
    BITMAPINFOHEADER stBIH = { 0 };
    file.Read( &stBIH, sizeof( stBIH ));

    // Convert to string
    csData += "\r\nBITMAPFILEHEADER\r\n";
    csStr.Format( "biSize          - %lu\r\n", stBIH.biSize );
    csData += csStr;
    csStr.Format( "biWidth         - %ld\r\n", stBIH.biWidth );
    csData += csStr;
    csStr.Format( "biHeight        - %ld\r\n", stBIH.biHeight );
    csData += csStr;
    csStr.Format( "biPlanes        - %u\r\n", stBIH.biPlanes );
    csData += csStr;
    csStr.Format( "biBitCount      - %lu\r\n", stBIH.biBitCount );
    csData += csStr;
    csStr.Format( "biCompression   - %lu\r\n", stBIH.biCompression );
    csData += csStr;
    csStr.Format( "biSizeImage     - %lu\r\n", stBIH.biSizeImage );
    csData += csStr;
    csStr.Format( "biXPelsPerMeter - %lu\r\n", stBIH.biXPelsPerMeter );
    csData += csStr;
    csStr.Format( "biYPelsPerMeter - %lu\r\n", stBIH.biYPelsPerMeter );
    csData += csStr;
    csStr.Format( "biClrUsed       - %lu\r\n", stBIH.biClrUsed );
    csData += csStr;
    csStr.Format( "biClrImportant  - %lu\r\n", stBIH.biClrImportant );
    csData += csStr;

    // RGBQUAD exists only if BitCount <= 8
    if( stBIH.biBitCount <= 8 )
    {
        // Read the RGBQUAD
        const int nSize = 1 << stBIH.biBitCount;
        RGBQUAD* arRGB = new RGBQUAD[nSize];
        file.Read( arRGB, nSize * sizeof( RGBQUAD ));

        csData += "\r\nRGBQUAD Array\r\n";
        for( int n = 0; n < nSize; n++ )
        {
            csStr.Format( "%02X %02X %02X %02X\r\n", arRGB[n].rgbBlue,arRGB[n].rgbGreen,
                                                     arRGB[n].rgbRed, arRGB[n].rgbReserved );
            csData += csStr;
        }
        delete[] arRGB;
    }
    else
    {
        csData += "\r\nRGBQUAD Array\r\nNone\r\n";
    }

    // Read the image data
    const int nSize = stBFH.bfSize - stBFH.bfOffBits;
    BYTE* arByte = new BYTE[nSize];
    file.Read( arByte, nSize );
    
    csData += "\r\nImage Data\r\n";

    for( int n = 0; n < nSize; n++ )
    {
        csStr.Format( "%02X ", arByte[n] );
        csData += csStr;
    }
    delete[] arByte;

    // Store to text box
    SetDlgItemText( IDC_EDIT_DATA, csData );
}


- NS -
[ODBaseBtn]

GeneralRe: convert image bitmap 8bits ??? wish help me Pin
Chris Losinger7-Nov-08 6:52
professionalChris Losinger7-Nov-08 6:52 
GeneralRe: convert image bitmap 8bits ??? wish help me Pin
aa_zz9-Nov-08 15:25
aa_zz9-Nov-08 15:25 
QuestionAdding one day Pin
AlProb6-Nov-08 23:04
AlProb6-Nov-08 23:04 
AnswerRe: Adding one day Pin
CPallini6-Nov-08 23:18
mveCPallini6-Nov-08 23:18 
GeneralRe: Adding one day Pin
AlProb6-Nov-08 23:25
AlProb6-Nov-08 23:25 
GeneralRe: Adding one day Pin
CPallini6-Nov-08 23:33
mveCPallini6-Nov-08 23:33 
QuestionConverting hexadecimal code into RGB Pin
Dhiraj kumar Saini6-Nov-08 22:13
Dhiraj kumar Saini6-Nov-08 22:13 
AnswerRe: Converting hexadecimal code into RGB Pin
CPallini6-Nov-08 22:36
mveCPallini6-Nov-08 22:36 
GeneralRe: Converting hexadecimal code into RGB Pin
Dhiraj kumar Saini6-Nov-08 22:49
Dhiraj kumar Saini6-Nov-08 22:49 
GeneralRe: Converting hexadecimal code into RGB Pin
CPallini6-Nov-08 22:52
mveCPallini6-Nov-08 22:52 
GeneralRe: Converting hexadecimal code into RGB Pin
Dhiraj kumar Saini6-Nov-08 23:34
Dhiraj kumar Saini6-Nov-08 23:34 
QuestionRe: Converting hexadecimal code into RGB Pin
David Crow7-Nov-08 2:45
David Crow7-Nov-08 2:45 
AnswerRe: Converting hexadecimal code into RGB Pin
CPallini7-Nov-08 3:31
mveCPallini7-Nov-08 3:31 
AnswerRe: Converting hexadecimal code into RGB Pin
sashoalm8-Nov-08 0:07
sashoalm8-Nov-08 0:07 
QuestionDraw on view and over their controls [modified] Pin
baerten6-Nov-08 21:53
baerten6-Nov-08 21:53 
AnswerRe: Draw on view and over their controls Pin
Nishad S7-Nov-08 1:48
Nishad S7-Nov-08 1:48 
GeneralRe: Draw on view and over their controls Pin
baerten7-Nov-08 4:20
baerten7-Nov-08 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.