Solved

How to print a Windows Bitmap file ?

Posted on 2000-04-03
8
319 Views
Last Modified: 2013-12-03
I'd like to send Windows Bitmap files to a printer.
Would it be possible to perform that task using PCL commands ?  Otherwise how to do that using Win32 APIs ?

Thanks

Edson
0
Comment
Question by:edsont
  • 3
  • 3
  • 2
8 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2680164
Hi edsont,

using PCL commands wouldn't be a good way coz it makes your program hardware dependant...

Better way: simply create a printer device context and a memory device context, load the bitmap, select it into the memory device context and from there blit it to the printer device context using StretchBlt() (or BitBlt() if you don't need scaling).

See help for PrintDlg, CreateCompatibleDC, SelectObject and StretchBlt...

you're welcome to ask if you have further question...

hope that helps,

ZOPPO
0
 

Author Comment

by:edsont
ID: 2680208
Zoppo,


Alternatively would you happen to know if PCL commands work in that context ?


Thanks

Edson
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2680253
If you need to use PCL commands (which is not recommended), you'll have to send your data directly (as raw data) to the printer without using the windows printer drivers. See MSDN article ID: Q138594 for how to do this.

ZOPPO
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 

Author Comment

by:edsont
ID: 2680315
Zoppo,

Two more questions:

1. Would you know which PCL commands could be used ?
2. Does it exist any MSDN sample using printer device context way but without MFC classes ?

Thanks

Edson
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 100 total points
ID: 2680365
1. Sorry, I don't have any knowledge about PCL.
2. I.e. MSDN article ID: Q139652 'Print a document'

again: It's strongly recommended to not use any hardware dependant printing. There's no advantage in using PCL. This would restrict your program to run only with printers which support PCL. Using windows GDI functions (based on device independant device context) is even simple and more flexible.

ZOPPO
0
 

Author Comment

by:edsont
ID: 2680501
My problem is that I already have a software that uses PCL commands to print. People asked for bitmap files printing but I wouldn't like to change it a lot.

Anyway I'll take atention to your suggestions.

Thanks

Edson
0
 

Expert Comment

by:jlislas
ID: 2753301
The writePrinter API function works with a printer handler. Tha printer handler can be obteined from an OpenPrinter API Function.

I think that if you create an array of bytes of your bitmaps, maybe you can print it using the writeprinter function.

I have the same problem, and the hard way is to send a Array of bytes for a BitMap through the writeprinter function

GetObject Picture1.Image, Len(PicInfo), PicInfo
'reallocate storage space
ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte
'Copy the bitmapbits to the array
GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'Invert the bits
For Cnt = 1 To UBound(PicBits)
PicBits(Cnt) = 255 - PicBits(Cnt)
Next Cnt
'Set the bits back to the picture
SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
0
 

Expert Comment

by:jlislas
ID: 2753302
The writePrinter API function works with a printer handler. Tha printer handler can be obteined from an OpenPrinter API Function.

I think that if you create an array of bytes of your bitmaps, maybe you can print it using the writeprinter function.

I have the same problem, and the hard way is to send a Array of bytes for a BitMap through the writeprinter function

GetObject Picture1.Image, Len(PicInfo), PicInfo
'reallocate storage space
ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte
'Copy the bitmapbits to the array
GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'Invert the bits
For Cnt = 1 To UBound(PicBits)
PicBits(Cnt) = 255 - PicBits(Cnt)
Next Cnt
'Set the bits back to the picture
SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question