Click here to Skip to main content
16,006,531 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Reading a bitmap Pin
CPallini29-Dec-06 23:12
mveCPallini29-Dec-06 23:12 
QuestionHandling the close(X) button Pin
Taruni29-Dec-06 21:11
Taruni29-Dec-06 21:11 
AnswerRe: Handling the close(X) button Pin
Michael Dunn29-Dec-06 21:30
sitebuilderMichael Dunn29-Dec-06 21:30 
QuestionHow to resize client are? Pin
hanlei000000000929-Dec-06 18:22
hanlei000000000929-Dec-06 18:22 
AnswerRe: How to resize client are? Pin
Hadi Dayvary29-Dec-06 18:45
professionalHadi Dayvary29-Dec-06 18:45 
GeneralSetWindowPos(), that OK! Thank you Pin
hanlei000000000930-Dec-06 14:15
hanlei000000000930-Dec-06 14:15 
QuestionIs any body help in DRM(Digital Rights Mgt) ,pDRMWriter->GenerateKeyID(w_KeyID,&d_KeyID); return S_FAIL Pin
amitmistry_petlad 29-Dec-06 17:56
amitmistry_petlad 29-Dec-06 17:56 
QuestionGetDIBits() works incorrectly with printer's DC Pin
Yuriy200329-Dec-06 15:22
Yuriy200329-Dec-06 15:22 
Hello, I need help with the following problem.

I am trying to print a PNG image with pixel-by-pixel transparency values. I know there are different ways to accomplish this, some printers have hardware support of the PNG and JPG formats. However, I am doing it in an old-fasioned way, to avoid as much as possible dependency on printer's capabilities.

I load PNG file, convert it into bitmap (32pits-per-pixel) with libpng library, then blend it with whatever background I have currently on a DC, and output the result. There are 2 ways to do this:

1. Using AlphaBlend() function. Unfortunately, none of the printers around (including some brand-new ones) report support for this function, i.e. (GetDeviceCaps(hDC, SHADEBLENDCAPS) & SB_PIXEL_ALPHA) is 0.

2. Reading the contents of the printer's device context using BitBlt() and GetDIBits() calls, manually blending the pixel values, and outputing the result to printer's DC. The printer device reports that it supports both BitBlt() and GetDIBits():

(GetDeviceCaps(hDC, RASTERCAPS) & RC_BITBLT) is non-zero
(GetDeviceCaps(hDC, RASTERCAPS) & RC_DI_BITMAP) is non-zero.

However, the call to GetDIBits() returns me all pixels on printer's DC as black. Here is my code:

//******************************************************************
// hDC is printer's DC in this case
HDC hCaptureDC = CreateCompatibleDC(hDC);
// img structure contains width, height, etc. for the image
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDC, img->width, img->height);
HGDIOBJ h = SelectObject(hCaptureDC, hCaptureBitmap);

ret = BitBlt(hCaptureDC, 0, 0, img->width, img->height, hDC, x, y, SRCCOPY);
if (ret == 0)
{
ret = GetLastError();
goto exit_proc;
}
memset (&bmpInfo, 0, sizeof(bmpInfo));
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biBitCount = 32;

// The bitmap identified by the hbmp parameter must not be selected into a device context when the //application calls this function (see MSDN page on GetDIBits), so deselect it:
SelectObject (hCaptureDC, h);

ret = GetDIBits(hCaptureDC,hCaptureBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
if (ret == 0)
{
ret = GetLastError();
goto exit_proc;
}
if (bmpInfo.bmiHeader.biBitCount != 32)
{
bmpInfo.bmiHeader.biBitCount = 32;
bmpInfo.bmiHeader.biSizeImage = 0;
}

if(bmpInfo.bmiHeader.biSizeImage<=0)
{
bmpInfo.bmiHeader.biSizeImage = mpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight) * ((bmpInfo.bmiHeader.biBitCount+7)/8);
}

if((pBuf = (BYTE *)malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
{
ret = -1;
goto exit_proc;
}

bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biBitCount = 32;
ret = GetDIBits(hCaptureDC,hCaptureBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);
if (ret == 0)
{
ret = GetLastError();
goto exit_proc;
}

//******************************************************************
Is there something I am doing wrong?
P.S. The above code works perfectly on screen DC. The problem occurs only with printers.
AnswerRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery30-Dec-06 8:06
Mark Salsbery30-Dec-06 8:06 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy200330-Dec-06 11:44
Yuriy200330-Dec-06 11:44 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery30-Dec-06 11:59
Mark Salsbery30-Dec-06 11:59 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy200330-Dec-06 12:43
Yuriy200330-Dec-06 12:43 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy20031-Jan-07 10:06
Yuriy20031-Jan-07 10:06 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery1-Jan-07 15:34
Mark Salsbery1-Jan-07 15:34 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy20032-Jan-07 11:08
Yuriy20032-Jan-07 11:08 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery2-Jan-07 11:28
Mark Salsbery2-Jan-07 11:28 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy20032-Jan-07 12:39
Yuriy20032-Jan-07 12:39 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery2-Jan-07 12:51
Mark Salsbery2-Jan-07 12:51 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy20032-Jan-07 13:03
Yuriy20032-Jan-07 13:03 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery2-Jan-07 13:46
Mark Salsbery2-Jan-07 13:46 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy20032-Jan-07 15:25
Yuriy20032-Jan-07 15:25 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery2-Jan-07 15:51
Mark Salsbery2-Jan-07 15:51 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Yuriy20032-Jan-07 18:20
Yuriy20032-Jan-07 18:20 
GeneralRe: GetDIBits() works incorrectly with printer's DC Pin
Mark Salsbery3-Jan-07 4:41
Mark Salsbery3-Jan-07 4:41 
GeneralRe: GetDIBits() works incorrectly with printer's DC [modified] Pin
Mark Salsbery3-Jan-07 5:46
Mark Salsbery3-Jan-07 5:46 

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.