Create a BitMap

This is a discussion on Create a BitMap within the Windows Programming forums, part of the Platform Specific Boards category; Hello... Somebody can help me in the creation of a BitMap, using only the functions listed on this URL: http://msdn.microsoft.com/library/de...tmaps_87eb.asp ...

  1. #1
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47

    Create a BitMap

    Hello...

    Somebody can help me in the creation of a BitMap, using only the functions listed on this URL:

    http://msdn.microsoft.com/library/de...tmaps_87eb.asp

    The attached picture, is the prototype to the BitMap that I try implement... Each frame represent a pixel... The colors must be correspondents...

    I enjoy any help...
    Attached Images Attached Images  

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    LoadBitmap and BitBlt will be your two best friends. That is of course if you are loading the bitmap from a .bmp file. If you want to make one on the fly then you're probably going to want to use CreateBitmap and still BitBlt.
    Don't quote me on that... ...seriously

  3. #3
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I can't load a BitMap of a file, for own motives...

    How make this BitMap using CreateBitmap() e BitBlt()?

    I studed the two functions but I continue with doubt...

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    So click on some links, read some example code and try and have a go at something. There's probably an example to do most of what you want if you look hard enough.

    You're not going to get much by saying "I want a foo, and use these functions".

    Or maybe go back to some simpler tutorials so you're more familiar with the basics of writing code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I'm studying by the book "Programming Windows, Charles Petzold", and by MSDN, too found some in the "WinProg Tutorial"...

    I'm with difficulty almost a week, want only a clue...

    So long...

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I'm with difficulty almost a week, want only a clue...
    Sorry to break the bad news to you but most of us here have been with difficulty on all our projects for far more than a week. Programming is all about solving problems and they never ever go away on new projects. They just get more complex and harder to solve.

    All you need to know is in the Platform SDK under Win32.

  7. #7
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    I'll give two hints, but it may not be a good way of doing it. First, look up "BITMAPINFOHEADER" in the SDK's documentation and learn the file format of BMPs. Figure these out and you can write all the BMP files you want. I do something similar for fixing up video frames (brightening and cropping), reading a BMP, fixing it, then writing the changed output.

  8. #8
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I make in this way...

    Code:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       static BYTE Map[ ] = {0xF7, 0xF7, 0xE3, 0xF7, 0xC1, 0xF7, 0x80, 0xF7};
       
       switch (message)
       {
          case WM_PAINT:
          {
             HBITMAP Bmp = CreateBitmap(9,5,1,1,&Map);
             
             HDC hdc = CreateCompatibleDC(GetDC(0));
             PAINTSTRUCT ps;
             
             SelectObject(hdc,Bmp);
             
             if(BeginPaint(hwnd,&ps))
             {
                BitBlt(ps.hdc,25,25,9,5,hdc,0,0,SRCCOPY);
                EndPaint(hwnd,&ps);
             }
          }break;
              
          case WM_DESTROY:
            PostQuitMessage (0);
            break;
          
          default:
            return DefWindowProc (hwnd, message, wParam, lParam);
       }
    
       return 0;
    }
    But yet be in black and white...

  9. #9
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    you can use CreateCompatibleBitmap with a DC, and then create another DC, use SelectObject with the dc and the bitmap and then you can draw on the bitmap.

  10. #10
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I make...

    Code:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       COLORREF In = RGB(0,0,255);
       COLORREF Out = RGB(255,0,0);
       
       COLORREF Map[45] = {Out, Out, Out, Out, Out, Out, Out, Out, Out,
                           In, Out, Out,Out, Out, Out, Out, Out, In,
                           In, In, Out, Out, Out, Out, Out, In, In,
                           In, In, In, Out, Out, Out, In, In, In,
                           In, In, In, In, Out, In, In, In, In,
                          };
    
       
       switch (message)
       {
          case WM_PAINT:
          {
             HDC hdc1, hdc2;
             HBITMAP hBmp;
             BITMAPINFO bi;
             PAINTSTRUCT ps;
             
             hdc1 = CreateCompatibleDC(hdc2 = GetDC(0));
             
             ZeroMemory(&bi.bmiHeader,sizeof(bi.bmiHeader));
             
             bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
             bi.bmiHeader.biWidth = 9;
             bi.bmiHeader.biHeight = 5;
             bi.bmiHeader.biPlanes = 1;
             bi.bmiHeader.biBitCount = 32;
             bi.bmiHeader.biCompression = BI_RGB;
             bi.bmiHeader.biSizeImage = bi.bmiHeader.biWidth * bi.bmiHeader.biHeight * (bi.bmiHeader.biBitCount/8);
             bi.bmiHeader.biXPelsPerMeter = bi.bmiHeader.biYPelsPerMeter = 0;
             
             hBmp = CreateDIBitmap(hdc2, &bi.bmiHeader, CBM_INIT, Map, &bi, DIB_RGB_COLORS);
             
             SelectObject(hdc1, hBmp);
             
             if(BeginPaint(hwnd,&ps))
             {
                BitBlt(ps.hdc,25,25,9,5,hdc1,0,0,SRCCOPY);
                EndPaint(hwnd,&ps);
             }
             
             DeleteDC(hdc1);
    
          }break;
               
          case WM_DESTROY:
            PostQuitMessage (0);
            break;
          
          default:
            return DefWindowProc (hwnd, message, wParam, lParam);
       }
    
       return 0;
    }

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    So was that your working answer, or do you still have some questions?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmap Displaying Problem
    By MadCow257 in forum Game Programming
    Replies: 0
    Last Post: 01-25-2005, 04:21 PM
  2. ResHacker error replacing bitmap file
    By 7stud in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2004, 06:54 AM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  5. graphics in win32 API
    By bennyandthejets in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2002, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21