How do I print bitmaps using the API?

How do I print bitmaps to the default printer using the Windows API?
ddg_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ddg_Author Commented:
Edited text of question.
0
mcriderCommented:
See the following microsoft page:

How to Print a VB Picture Control Using Windows API Functions
http://support.microsoft.com/support/kb/articles/Q77/0/60.ASP?LNG=ENG&SA=MSDN 
 

It's a 16-bit example, but all you have to do is use the 32-bit API calls.  You can find them in the API Text Viewer...


Cheers!
0
ddg_Author Commented:
Thanx mcrider, but I am trying to print bitmap files without using picturebox controls.  I do not want to load a bitmap into a picturebox each time before printing it.  Do you or anyone else know of a way to do this?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vbyuvalCommented:
?
0
ddg_Author Commented:
The problem I am experiencing with pictureboxes is that they must be visible in order to print them.
Basically, I want to load a bitmap from a file into memory, and then manipulate the memory's hdc to print it to the printer.
0
mcriderCommented:
pictureboxes DO NOT need to be visible to print them...


Cheers!
0
KhollADCommented:
You can use the Loadimage Api to open a bmp in memory without use picturebox and then print this bmp with the blt and escape features.

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As BITMAP) As Long

Private Type BITMAP '14 bytes
        bmType As Long
        bmWidth As Long
        bmHeight As Long
        bmWidthBytes As Long
        bmPlanes As Integer
        bmBitsPixel As Integer
        bmBits As Long
End Type


Private Declare Function Escape Lib "gdi32" (ByVal hdc As Long, ByVal nEscape As Long, ByVal nCount As Long, ByVal lpInData As String, lpOutData As Any) As Long


Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Private Const SRCCOPY = &HCC0020

Private Buffer, Buffer_hBitmap As Long

Private Sub BmpPrint(FileName As String)

    Dim lRet As Long
   
    Dim BmpInfo As BITMAP
   
    Printer.ScaleMode = 1
   
    Printer.Print ""
   
    Buffer = CreateCompatibleDC(0)
   
    Buffer_hBitmap = LoadImage(ByVal 0&, FileName, 0, 0, 0, &H10)
   
    lRet = SelectObject(Buffer, Buffer_hBitmap)
   
    lRet = GetObject(Buffer_hBitmap, Len(BmpInfo), BmpInfo)
   
    lRet = StretchBlt(Printer.hdc, 0, 0, Printer.ScaleX(BmpInfo.bmWidth, 3, 1), Printer.ScaleY(BmpInfo.bmHeight, 3, 1), Buffer, 0, 0, BmpInfo.bmWidth, BmpInfo.bmHeight, SRCCOPY)
   
    lRet = DeleteDC(Buffer)
    lRet = DeleteObject(Buffer_hBitmap)
   
    lRet = Escape(Printer.hdc, 1, 0, 0&, 0&)
   
    Printer.EndDoc

End Sub

Private Sub Command1_Click()

    Call BmpPrint("c:\mypic.bmp")
   
End Sub



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.