Click here to Skip to main content
15,914,413 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 8:40
Mark Salsbery2-Oct-07 8:40 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery3-Oct-07 12:59
Mark Salsbery3-Oct-07 12:59 
AnswerRe: Need a best possible alternative?? Pin
Nelek27-Sep-07 21:19
protectorNelek27-Sep-07 21:19 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish1-Oct-07 10:46
Kiran Satish1-Oct-07 10:46 
GeneralRe: Need a best possible alternative?? Pin
Nelek2-Oct-07 10:19
protectorNelek2-Oct-07 10:19 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery9-Oct-07 6:04
Mark Salsbery9-Oct-07 6:04 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish18-Jun-08 17:55
Kiran Satish18-Jun-08 17:55 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery19-Jun-08 6:40
Mark Salsbery19-Jun-08 6:40 
The easiest and most flexible way to do that is to create a DIBsection and copy your pixel bits
into it.  That gives you an HBITMAP you can select into DCs, and also a pointer to the pixel
bits so you can directly manipulate them.

Here's an example of the basic stuff for creating an 8bpp grayscale DIBSection:
    LONG lImageWidth = 640;
    LONG lImageHeight = 480;
    WORD wBitsPerPixel = 8;
 
    LONG lStride = (((lImageWidth * (long)wBitsPerPixel + 31L) & (~31L)) / 8L);
 
    BITMAPINFO *bm = (BITMAPINFO *)new BYTE[sizeof(BITMAPINFO) + 255 * sizeof(RGBQUAD)];

    bm->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bm->bmiHeader.biWidth = lImageWidth;
    bm->bmiHeader.biHeight = lImageHeight;
    bm->bmiHeader.biPlanes = 1;
    bm->bmiHeader.biBitCount = wBitsPerPixel;
    bm->bmiHeader.biCompression = BI_RGB;
    bm->bmiHeader.biSizeImage = 0;
    bm->bmiHeader.biXPelsPerMeter = 0;
    bm->bmiHeader.biYPelsPerMeter = 0;
    bm->bmiHeader.biClrUsed = 0;
    bm->bmiHeader.biClrImportant = 0;

    for (int color_index = 0; color_index < 256; color_index++)
    {
        bm->bmiColors[color_index].rgbBlue = color_index;
        bm->bmiColors[color_index].rgbGreen = color_index;
        bm->bmiColors[color_index].rgbRed = color_index;
        bm->bmiColors[color_index].rgbReserved = 0;
    }

    BYTE *pBitmapBits;
    HBITMAP hBitmap = ::CreateDIBSection(NULL, bm, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);

    if (hBitmap)
    {
        // do something with the DIBSection

        ::DeleteObject(hBitmap);
    }

    delete[] (BYTE *)bm;
Copy your captured 8-bit pixel data to the array pointed to by pBitmapBits.

lStride is the length of each row in bytes - there may be extra bytes at the
end of each row so make sure you take that into account.

You can use hBitmap just like any DDB.  You can select it into a memory DC and draw on it
with GDI functions, blt it to the screen, etc.

Mark



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

QuestionCString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 6:41
Mike Borozdin27-Sep-07 6:41 
QuestionRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 7:20
David Crow27-Sep-07 7:20 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 7:47
Mike Borozdin27-Sep-07 7:47 
QuestionRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 7:51
David Crow27-Sep-07 7:51 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 8:09
Mike Borozdin27-Sep-07 8:09 
QuestionRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 8:14
David Crow27-Sep-07 8:14 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 8:43
Mike Borozdin27-Sep-07 8:43 
QuestionRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 8:46
David Crow27-Sep-07 8:46 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 9:10
Mike Borozdin27-Sep-07 9:10 
GeneralRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 9:16
David Crow27-Sep-07 9:16 
GeneralRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 9:30
Mike Borozdin27-Sep-07 9:30 
GeneralRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 9:34
David Crow27-Sep-07 9:34 
GeneralRe: CString to char* leads to an exception Pin
Mark Salsbery27-Sep-07 8:38
Mark Salsbery27-Sep-07 8:38 
GeneralRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 8:44
Mike Borozdin27-Sep-07 8:44 
QuestionDDE Question Pin
__DanC__27-Sep-07 6:18
__DanC__27-Sep-07 6:18 
Questionextend the "Save As..." dialog Pin
carabutnicolae123427-Sep-07 5:39
carabutnicolae123427-Sep-07 5:39 
AnswerRe: extend the "Save As..." dialog Pin
Nelek28-Sep-07 0:37
protectorNelek28-Sep-07 0:37 

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.