-
July 5th, 2012, 08:43 AM
#1
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:oPrintJob(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);
:eleteDC(hDC);
return 0;
}
-
July 5th, 2012, 04:10 PM
#2
Re: printer not showing the image properly.
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.
Best regards,
Igor
-
July 5th, 2012, 04:57 PM
#3
Re: printer not showing the image properly.
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?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 10th, 2012, 08:26 AM
#4
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?.
Last edited by rohitnegi; July 10th, 2012 at 08:28 AM.
-
July 10th, 2012, 04:18 PM
#5
Re: printer not showing the image properly.
Best regards,
Igor
-
July 31st, 2012, 04:45 AM
#6
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:rint(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);
:eleteDC(hDC);
}
-
July 31st, 2012, 05:04 AM
#7
Re: printer not showing the image properly.
images get distorted(stretch or shrink)
Compared to image, Print's width and height should be corrected to have the same aspect ratio.
Best regards,
Igor
-
August 3rd, 2012, 12:36 PM
#8
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.
-
August 4th, 2012, 01:42 AM
#9
Re: printer not showing the image properly.
It does not print without any error reported? Do you check error codes in your code?
Best regards,
Igor
-
August 6th, 2012, 09:25 AM
#10
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.
Last edited by rohitnegi; August 8th, 2012 at 09:57 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|