Solved

How to print a Windows Bitmap file ?

Posted on 2000-04-03
8
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

635 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