測試印表機是否支援 JPEG 或 PNG
SetDIBitsToDevice函式會使用 DIB 的色彩資料,在與目的地裝置內容相關聯的裝置上,設定指定矩形中的圖元。
SetDIBitsToDevice 會擴充為允許 JPEG 或 PNG 映射當做來源映射傳遞。
例如:
//
// pvJpgImage points to a buffer containing the JPEG image
// nJpgImageSize is the size of the buffer
// ulJpgWidth is the width of the JPEG image
// ulJpgHeight is the height of the JPEG image
//
//
// Check if CHECKJPEGFORMAT is supported (device has JPEG support)
// and use it to verify that device can handle the JPEG image.
//
ul = CHECKJPEGFORMAT;
if (
// Check if CHECKJPEGFORMAT exists:
(ExtEscape(hdc, QUERYESCSUPPORT,
sizeof(ul), &ul, 0, 0) > 0) &&
// Check if CHECKJPEGFORMAT executed without error:
(ExtEscape(hdc, CHECKJPEGFORMAT,
pvJpgImage, nJpgImageSize, sizeof(ul), &ul) > 0) &&
// Check status code returned by CHECKJPEGFORMAT:
(ul == 1)
)
{
//
// Initialize the BITMAPINFO.
//
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = ulJpgWidth;
bmi.bmiHeader.biHeight = -ulJpgHeight; // top-down image
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 0;
bmi.bmiHeader.biCompression = BI_JPEG;
bmi.bmiHeader.biSizeImage = nJpgImageSize;
//
// Do the SetDIBitsToDevice.
//
iRet = SetDIBitsToDevice(hdc,
ulDstX, ulDstY,
ulDstWidth, ulDstHeight,
0, 0,
0, ulJpgHeight,
pvJpgImage,
&bmi,
DIB_RGB_COLORS);
if (iRet == GDI_ERROR)
return FALSE;
}
else
{
//
// Decompress image into a DIB and call SetDIBitsToDevice
// with the DIB instead.
//
}