No color image by using PXC_AddImageFromHBITMAP

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Support Staff, moderators

Post Reply
ZSubotic
User
Posts: 4
Joined: Mon Aug 11, 2008 10:59 am

No color image by using PXC_AddImageFromHBITMAP

Post by ZSubotic » Mon Aug 11, 2008 11:12 am

I'm trying to add an image into pdf-document by using function “PXC_AddImageFromHBITMAP”. It appears mohnochrome by using following code:

void CPDFExchange::PasteBitmap(int iBreite, int iHoehe, LPRECMEMO pRecMemo, int iPosX, int iPosY)
{
BOOL bOk = FALSE;
_PXCImage *pImage = NULL;
HDC hMemDc = CreateCompatibleDC(m_pForm->Printer.hDcPrn);
if (hMemDc)
{
SetMapMode(hMemDc, GetMapMode(m_pForm->Printer.hDcPrn));
HBITMAP hBmp = CreateCompatibleBitmap(m_pForm->Printer.hDcPrn, iBreite, iHoehe);
if (hBmp)
{
HBITMAP hOldBmp = (HBITMAP)SelectObject(hMemDc, hBmp);
PatBlt(hMemDc, 0, 0, iBreite, iHoehe, WHITENESS);
MetaPlayMemo(m_pForm, hMemDc, pRecMemo);
BitBlt(m_pForm->Printer.hDcPrn, 0, 0, iBreite, iHoehe, hMemDc, 0, 0, SRCCOPY);
SelectObject(hMemDc, hOldBmp);

if (PXC_OK == PXC_AddImageFromHBITMAP(m_pdf, hBmp, NULL, &pImage))
bOk = (PXC_OK == PXC_PlaceImage(m_Page, pImage, m_x * (iPosX + m_OffsetX),
m_PaperLength - (m_y * (iPosY + m_pForm->yOff + m_OffsetY)),
m_x * iBreite,
m_y * iHoehe));
DeleteObject(hBmp);
}

DeleteDC(hMemDc);
}
}

If I change the device context parameter:
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(NULL), iBreite, iHoehe);

it is possible to save the content into bmp-file, it looks good, but I cannot add it into my pdf-document. Pdf is empty.
Any ideas?

Best regards Zoran.

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: No color image by using PXC_AddImageFromHBITMAP

Post by Ivan - Tracker Software » Thu Aug 14, 2008 3:38 pm

Hi,

firstly, why image is monochrome? See this snippet from the MSDN documentation for the CreateCompatibeBitmap function:
The color format of the bitmap created by the CreateCompatibleBitmap function matches the color format of the device identified by the hdc parameter. This bitmap can be selected into any memory device context that is compatible with the original device.

Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color palette as the specified device context.

Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the hDC that was used to create the memory device context, as shown in the following code:
Second, why bitmap is the empty when you use GetDC(NULL)?

Could it be that the memory DC you have created is from the desktop DC too ?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

ZSubotic
User
Posts: 4
Joined: Mon Aug 11, 2008 10:59 am

Re: No color image by using PXC_AddImageFromHBITMAP

Post by ZSubotic » Tue Aug 19, 2008 12:13 pm

You should be right that the monochrome bitmap matches the color format of the device context (in my case: m_pForm->Printer.hDcPrn). That’s why I tried screen device (GetDC(NULL)).

Now, if I save the created bitmap as a file, it appears in color. I expect, when I add this bitmap into pdf-document it should work. It doesn’t. It is just a question!!!, if you have ever had problems with the function, probably I must change my code.

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: No color image by using PXC_AddImageFromHBITMAP

Post by Ivan - Tracker Software » Thu Aug 21, 2008 2:31 pm

Can you send me your sample project ?

Please ZIP any files attached here and ensure that no serial numbers are embedded in your code.

Thanks
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

Post Reply