Solved

Unable to create color bitmap in Compatible Device Context

Posted on 1998-06-16
1
288 Views
Last Modified: 2008-03-17
/* Unable to create color bitmap in Compatible Device Context */
I try to do some manipulation on the drawing right before printing (function BitBlt)
unfortunately when I print, I loose all color informations, It seems that the bitmaps that I create
by calling CreateCompatibleBitmap returns handle to monochrome Bitmaps. I really doesn't know what to do
to create color bitmap */



BOOL PrintSelect180Rotation (HWND hwnd, FPOINT Pt1,FPOINT Pt2 )
     {
     static DOCINFO di     = { sizeof (DOCINFO), "Print1: Printing", NULL } ;
     BOOL           bError = FALSE ;
     HDC            hdcPrn,hdcMem,hdcMem2;
     int            i,j,xPageMem,yPageMem ;
    HPALETTE hPalette;
       PBITMAPINFO pbmi;
       HBITMAP hBmp = NULL;
    HBITMAP hBmp2 = NULL;
    HBITMAP hbtest = NULL;


       char mes[256];
       int  Max_select_y,Max_select_x,select_x,select_y;

    /* Get Printer DC  Presently I'am using HP PaintJet XL 300*/
    if (NULL == (hdcPrn = GetPrinterDC(hwnd)))
          return TRUE ;

    xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
       yPage = GetDeviceCaps (hdcPrn, VERTRES) ;

    /* Create DC temporary using for storing some drawing */
    hdcMem = CreateCompatibleDC(hdcPrn);
    hdcMem2 = CreateCompatibleDC(hdcPrn);
    /* Create Bitmaps to store drawing */
    hBmp = CreateCompatibleBitmap(hdcMem,xPage,yPage);    /*!!!!!<----- Bitmap, I get from  is monochrome bitmap
                                                                                                                      but I need to  create color bitmaps.  */
    hBmp2 = CreateCompatibleBitmap(hdcMem2,xPage,yPage);
    /* Selecting Bitmaps into memory */
    SelectObject(hdcMem,hBmp);
    SelectObject(hdcMem2,hBmp2);
    /* Initialization of the contents of the Bitmaps */
    PatBlt(hdcMem,0,0,xPage,yPage,WHITENESS);
    PatBlt(hdcMem2,0,0,xPage,yPage,WHITENESS);
    /*Keeping the same map mode */
    SetMapMode(hdcMem, GetMapMode(hdcPrn));

    /* Setting  global data for WM_PAINT */
    xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
       yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
    /* Drawing in the bitmap*/
    DrawData(hwnd,hdcMem,TRUE,FALSE);


    pbmi = CreateBitmapInfoStruct(hwnd,hBmp);
    CreateBMPFile(hwnd, "d:\\Image.bmp", pbmi,hBmp, hdcMem) ;
       select_x = Pt1.x *xPage;
       select_y = Pt1.y *yPage;
       Max_select_x =      Pt2.x *xPage - select_x;
       Max_select_y = Pt2.y *yPage - select_y;

          if((GetDeviceCaps(hdcPrn,RASTERCAPS) & RC_BITBLT)==0 || (GetDeviceCaps(hdcMem,RASTERCAPS & RC_BITBLT)==0 ))
            {
            MessageBox(hwnd,"BLTBIT not suported","Impossible a imprimer",0L);
               DeleteDC (hdcPrn) ;
                 DeleteObject(hBmp);
                 DeleteObject(hBmp2);
                 return bError ;
         }

      /*        rotating a bitmap by 180 degrees */
       BitBlt(hdcMem2 ,0,0,xPageMem,yPageMem,hdcMem,0,0,SRCCOPY);
            for(i = 0;i<Max_select_y;i++)
                         BitBlt(hdcMem,select_x,select_y+i,Max_select_x,1,hdcMem2,select_x,select_y + Max_select_y -i,SRCCOPY);

              BitBlt(hdcMem2 ,0,0,xPageMem,yPageMem,hdcMem,0,0,SRCCOPY);
            for(i = 0;i<Max_select_x;i++)
                   BitBlt(hdcMem,select_x+i,select_y,1,Max_select_y,hdcMem2,select_x + Max_select_x -i,select_y ,SRCCOPY);

    /* Printing */
     if (StartDoc (hdcPrn, &di) > 0)
          {
          if (StartPage (hdcPrn) > 0)
               {
               xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
                               yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
               xPageMem = GetDeviceCaps (hdcMem, HORZRES) ;
                           yPageMem = GetDeviceCaps (hdcMem, VERTRES) ;
                              StretchBlt(hdcPrn,0,0,xPage,yPage,hdcMem,0,0,xPageMem,yPageMem, SRCCOPY);
               if (EndPage (hdcPrn) > 0)
                    EndDoc (hdcPrn) ;
               else
                    bError = TRUE ;
               }
          }
     else
          bError = TRUE ;

     DeleteDC (hdcPrn) ;
     DeleteObject(hBmp);
     DeleteObject(hBmp2);
     return bError ;
     }

0
Comment
Question by:mvylita
1 Comment
 
LVL 1

Accepted Solution

by:
Andy_Keys earned 100 total points
Comment Utility
When a dc is created its bitmap by default is a 1*1 monochrome bitmap. Create a bitmap by doing something like
CreateBitmap( Width, Height, MemDC.GetDeviceCaps( PLANES ), MemDC.GetDeviceCaps( BITSPIXEL ), NULL ); instead of CreateCompatibleBitmap this should be a colour bitmap.  NOTE as the DC is a printer DC just make sure that the calls to Get DeviceCaps return sensible values ie one of them should not be one else you still get a monochrome bitmap


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now