Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to print a Windows Bitmap file ?

Posted on 2000-04-03
8
Medium Priority
?
366 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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 300 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

963 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