printer not showing the image properly.
Below is the code that prints image but image width and height is very less.
Suppose if my image width = 900 and height=600 then it prints the image with width around 60 and height around 70 . What can be problem ?
DWORD CDemo1Dlg::DoPrintJob(LPTSTR szPrinterName)//szPrinterName is path of the printer in the network
{
DWORD dwError = 0;
TCHAR szJobName[128] = {0};
HDC hDC = 0;
DOCINFO DocInfo;
BITMAPINFO BmpInfo;
int nRet = 0;
HBITMAP hBmp24 = 0;
BITMAP Bmp24 = {0};
LOGFONT LogFont = {0};
HFONT hFont = 0,
hDefFont = 0;
if ( !m_Bmp24Name.IsEmpty() )
{
hBmp24 = (HBITMAP) LoadImage(0, (LPCTSTR)m_Bmp24Name, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
dwError = GetLastError();
GetObject(hBmp24, sizeof(BITMAP), &Bmp24);
}
hDC = CreateDC(_T("WINSPOOL"), szPrinterName, NULL, 0);
if ( dwError )
return dwError;
//4. StartDoc
memset(&DocInfo, 0, sizeof(DOCINFO));
DocInfo.cbSize = sizeof(DOCINFO);
lstrcpy(szJobName, _T("Test"));
DocInfo.lpszDocName = szJobName;
nJobId = ::StartDoc(hDC, &DocInfo);
//5. StartPage
nRet = ::StartPage(hDC);
//6.b Draw anything you want on page between ::StartPage and ::EndPage
if ( Bmp24.bmBits )
{
memset(&BmpInfo, 0, sizeof(BITMAPINFO));
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BmpInfo.bmiHeader.biWidth = Bmp24.bmWidth;
BmpInfo.bmiHeader.biHeight = Bmp24.bmHeight;
BmpInfo.bmiHeader.biPlanes = Bmp24.bmPlanes;
BmpInfo.bmiHeader.biBitCount = Bmp24.bmBitsPixel * Bmp24.bmPlanes;
BmpInfo.bmiHeader.biCompression = BI_RGB;
nRet = StretchDIBits(hDC, 0, 0, Bmp24.bmWidth, Bmp24.bmHeight, 0, 0, Bmp24.bmWidth, Bmp24.bmHeight, Bmp24.bmBits, &BmpInfo, DIB_RGB_COLORS, SRCCOPY);
}
//7. If page drawing is finished, set to end page
nRet = ::EndPage(hDC);
//8. If job done, set end of the job
nRet = ::EndDoc(hDC);
//release image object
if ( hBmp24 )
DeleteObject(hBmp24);
::DeleteDC(hDC);
return 0;
}
Re: printer not showing the image properly.
Quote:
What can be problem ?
The problem is in different device capabilities. Printer has physical resolution different from pixels, therefore you need to translate pixel sizes to device-specific sizes.
Re: printer not showing the image properly.
Quote:
Originally Posted by
rohitnegi
Suppose if my image width = 900 and height=600 then it prints the image with width around 60 and height around 70
900 of what? And 60 of what?
Re: printer not showing the image properly.
yes, after getting the device width and height using GetDeviceCaps(), Printer showing the image as per the printer page height and width. I am able to print the .bmp file but it does not print .jpg and .png images. how can i print .jpg and .png file format?.
Re: printer not showing the image properly.
Re: printer not showing the image properly.
Using CImage i can print any kind of image. But when i try to print 4*6 image then images get distorted(stretch or shrink). What should i do?.
Following is the code .
void PrinterJob::print(CString printerName,CString imageName,int width, int height)
{
TCHAR szJobName[128] = {0};
HDC hDC = 0;
DOCINFO DocInfo;
int nJobId = 0;
int nRet = 0;
CImage image;
//2. CreateDC
hDC = CreateDC(_T("WINSPOOL"), printerName, NULL, 0);
//4. StartDoc
memset(&DocInfo, 0, sizeof(DOCINFO));
DocInfo.cbSize = sizeof(DOCINFO);
lstrcpy(szJobName, _T("Test"));
DocInfo.lpszDocName = szJobName;
nJobId = ::StartDoc(hDC, &DocInfo);
nRet = ::StartPage(hDC);
if(nRet)
{
image.Load(imageName);
int xDpi =GetDeviceCaps(hDC, LOGPIXELSX);// to get the dpi
int yDpi = GetDeviceCaps(hDC, LOGPIXELSY);
printResult = image.StretchBlt(hDC,250,200,xDpi*width,yDpi*height, 0, 0, image.GetWidth(), image.GetHeight(), SRCCOPY);
}
//7. If page drawing is finished, set to end page
nRet = ::EndPage(hDC);
//8. If job done, set end of the job
nRet = ::EndDoc(hDC);
::DeleteDC(hDC);
}
Re: printer not showing the image properly.
Quote:
images get distorted(stretch or shrink)
Compared to image, Print's width and height should be corrected to have the same aspect ratio.
Re: printer not showing the image properly.
After using aspect ratio, printer showing images good.
When i try to use this code to photo printer, it does not print the image. Do i have to modify the code to make it to work for photo printer?. I am using Hiti Photo Printer.
Re: printer not showing the image properly.
It does not print without any error reported? Do you check error codes in your code?
Re: printer not showing the image properly.
My Code executes completely but HiTi photo printer gives warning "Ribon type mismatch" and error code 524800.
that was problem from printer setting. It is working now after setting the page size same as ribbon size in the printer.