This test with DrawImage and ColorMatrix does not seem too slow :
WCHAR wsURL[MAX_PATH] = TEXT("https://image.ibb.co/buLv2e/Little_Girl3.jpg");
WCHAR wsFilename[MAX_PATH];
HRESULT hr = URLDownloadToCacheFile(NULL, wsURL, wsFilename, ARRAYSIZE(wsFilename), 0x0, NULL);
if (SUCCEEDED(hr))
{
{
PrintBitmapAlphaBlend(wsFilename, DMORIENT_PORTRAIT, 0.5f);
return 0;
}
}
// GdiplusStartup at beginning
// https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-use-a-color-matrix-to-set-alpha-values-in-images?view=netframeworkdesktop-4.8
void PrintBitmapAlphaBlend(LPWSTR wsFilename, int nOrientation, float fAlpha)
{
HDC hDCPrinter = NULL;
PRINTDLG pd;
ZeroMemory(&pd, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
PrintDlg(&pd);
hDCPrinter = pd.hDC;
DEVMODE* dm = (DEVMODE*)GlobalLock(pd.hDevMode);
dm->dmOrientation = nOrientation;
ResetDC(pd.hDC, dm);
GlobalUnlock(pd.hDevMode);
ColorMatrix cm = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, fAlpha, 0.0f,
0.0f, 0.0f, 0.0f ,0.0f, 1.0f
};
ImageAttributes ia;
ia.SetColorMatrix(&cm, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
Image img(wsFilename);
UINT nImageWidth = img.GetWidth();
UINT nImageHeight = img.GetHeight();
Graphics* gr = new Graphics(hDCPrinter);
gr->SetPageUnit(UnitPixel);
DOCINFO di;
ZeroMemory(&di, sizeof(di));
di.cbSize = sizeof(di);
di.lpszDocName = TEXT("Image Printing");
if (StartDoc(hDCPrinter, &di))
{
if (StartPage(hDCPrinter))
{
int nPrinterWidth = GetDeviceCaps(hDCPrinter, HORZRES);
int nPrinterHeight = GetDeviceCaps(hDCPrinter, VERTRES);
int nBitmapWidth = nImageWidth * nPrinterWidth / GetSystemMetrics(SM_CXSCREEN);
int nBitmapHeight = nBitmapWidth * nImageHeight / nImageWidth;
Bitmap* bitmap = new Bitmap(nPrinterWidth, nPrinterHeight, PixelFormat32bppARGB);
Graphics* g = Graphics::FromImage(bitmap);
for (int x = 0; x < nPrinterWidth; x += nBitmapWidth)
{
for (int y = 0; y < nPrinterHeight; y += nBitmapHeight)
{
g->DrawImage(&img, x, y, nBitmapWidth, nBitmapHeight);
}
}
delete g;
//RectF rectF(0, 0, nBitmapWidth, nBitmapHeight);
RectF rectF(0, 0, nPrinterWidth, nPrinterHeight);
/*gr->DrawImage(&img, rectF, 0, 0, nImageWidth, nImageHeight, UnitPixel, &ia);*/
gr->DrawImage(bitmap, rectF, 0, 0, nPrinterWidth, nPrinterHeight, UnitPixel, &ia);
delete bitmap;
EndPage(hDCPrinter);
}
EndDoc(hDCPrinter);
}
delete gr;
DeleteDC(hDCPrinter);
}
Original image :
Result :