CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    26

    [RESOLVED] Creating and Drawing Monochrome Bitmap from CHAR array

    Hello, I have a function that will find pixels (of a certain color) in a DC that are grouped together. Like an ellipse, or really any shape. The dimensions of the data is stored inside a RECT structure, and the found pixels are in a Character array, arranged like a monochrome bitmap (1 bit per pixel).
    I am trying to visually display the result on the screen in the form of a monochrome bitmap, I've already tested the function by displaying the results in a console window so I know the FindClusters function is working perfectly, I simple can't draw the results on screen. When I try to, I get a mess of black and white pixels on the screen. Here is my code.
    Code:
    bool DrawCluster (HDC hDC, CLUSTER* Source)
    {
        // If the cluster is empty don't try to do any operations on it.
        if (Source == NULL) return false;
     
        // The width and height of the source cluster
        int Source_Width = abs((*Source).Rect.right - (*Source).Rect.left) + 1;
        int Source_Height = abs((*Source).Rect.bottom - (*Source).Rect.top) + 1;
     
        HBITMAP Buffer_Bitmap = CreateBitmap (Source_Width, Source_Height, 1, 1, (*Source).Data);
        HDC Buffer = CreateCompatibleDC (NULL);
        SelectObject (Buffer, Buffer_Bitmap);
     
        return (BitBlt (hDC, 0, 0, Source_Width, Source_Height, Buffer, 0, 0, SRCCOPY) != 0);
    }
    I really have no idea where the problem is, but I know it's in this function. Does anyone have any ideas or a good example/article? Thanks everyone!

  2. #2
    Join Date
    Apr 2008
    Posts
    26

    Re: Creating and Drawing Monochrome Bitmap from CHAR array

    Someone on another website has helped me out. The problem was in how I was formatting the CHAR array I was passing to CreateBitmap. Sorry for the empty thread, if a mod could just delete this I'd appreciate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured