Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Picture using printer object

Status
Not open for further replies.

JeffSabat

Programmer
Sep 15, 2003
32
PH
i am developing a program that will print a picture to the card... my problem is i can't get the picture printed exactly to the printer.
i use this command...
Printer.PaintPicture Form1.Picture1, 0, 0

picture1 is the exact size i want it to be...
however, the printed one is smaller in size...
i think it's pixels stuff and all that but i really don't know how to manipulate it.
The first thing i did was edit the picture in adobe photoshop then print it at ms word to check the exact size.
Then i import the picture in my VB program in the control form1.picture1.
I thought it was alryt until i run my program when it printed a smaller picture...
please help me what to do.. i'm already tired editing the picture in adobe, doing a trial and error stuff...
 

You are missing (or not using) a lot of the optional arguements of the paintpicture method.

From VB's Help
[tt]
PaintPicture Method


Draws the contents of a graphics file (.bmp, .wmf, .emf, .cur, .ico, or .dib) on a Form, PictureBox, or Printer. Doesn't support named arguments.

Syntax

object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2, height2, opcode

The PaintPicture method syntax has these parts:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the Form object with thefocus is assumed to be object.

Picture Required. The source of the graphic to be drawn onto object. Must be the Picture property of a Form or PictureBox.

x1, y1 Required. Single-precision values indicating the destination coordinates (x-axis and y-axis) on object for picture to be drawn. The ScaleMode property of object determines the unit of measure used.

Width1 Optional. Single-precision value indicating the destination width of picture. The ScaleMode property of object determines the unit of measure used. If the destination width is larger or smaller than the source width (width2), picture is stretched or compressed to fit. If omitted, the source width is used.

Height1 Optional. Single-precision value indicating the destination height of picture. The ScaleMode property of object determines the unit of measure used. If the destination height is larger or smaller than the source height (height2), picture is stretched or compressed to fit. If omitted, the source height is used.

x2, y2 Optional. Single-precision values indicating the coordinates (x-axis and y-axis) of a clipping region within picture. The ScaleMode property of object determines the unit of measure used. If omitted, 0 is assumed.

Width2 Optional. Single-precision value indicating the source width of a clipping region within picture. The ScaleMode property of object determines the unit of measure used. If omitted, the entire source width is used.

Height2 Optional. Single-precision value indicating the source height of a clipping region within picture. The ScaleMode property of object determines the unit of measure used. If omitted, the entire source height is used.

Opcode Optional. Long value or code that is used only withbitmaps. It defines a bit-wise operation (such as vbMergeCopy or vbSrcAnd) that is performed on picture as it's drawn on object. For a complete list of bit-wise operator constants, see the RasterOp Constants topic in Visual Basic Help.
There are some limitations in the usage of opcodes. For example, you can't use any opcode other than vbSrcCopy if the source is an icon or metafile, and the opcodes that interact with the pattern (or "brush" in SDK terms) such as MERGECOPY, PATCOPY, PATPAINT, and PATINVERT actually interact with the FillStyle property of the destination.

Note Opcode is used to pass a bitwise operation on a bitmap. Placing a value in this argument when passing other image types will cause an "Invalid procedure call or argument" error. This is by design. To avoid this error, leave the Opcode argument blank for any image other than a bitmap.



Remarks

You can flip a bitmap horizontally or vertically by using negative values for the destination height (height1) and/or the destination width (width1).

You can omit as many optional trailingarguments as you want. If you omit an optional trailing argument or arguments, don't use any commas following the last argument you specify. If you want to specify an optional argument, you must specify all optional arguments that appear in thesyntax before it.

Note that there is a difference between loading a .Bmp into a PictureBox control, and using the Windows API function BitBlt() to add a picture to it. When you BitBlt an image, the PictureBox control doesn't know to resize like it does if you use the LoadPicture method. Setting the ScaleWidth and ScaleHeight properties to the size of the image also doesn't work. If you want the PictureBox to resize to the new picture after BitBlt'ing, you must do so manually by code, converting units and dealing with borders. Below is a simple example of how to do this:

Sub ResizePictureBoxToImage(pic as PictureBox, twipWd _
as Integer, twipHt as Integer)
' This code assumes that all units are in twips. If
' not, you must convert it to twips before calling
' this routine. This also assumes that the image
' was blt'ed to 0,0.
Dim BorderHt as Integer, BorderWd as Integer
BorderWd = Pic.Width - Pic.ScaleWidth
BorderHt = Pic.Height - Pic.ScaleHeight
pic.Move pic.Left, pic.Top, twipWd + BorderWd, _
twipHt + BorderHt
End Sub
[/tt]

So to get the image to print just like you want you will have to include some of these optional arguements.

However you must note that a printers DPI can be much higher than a screens DPI which you will understand if you stretch the picture to much you will get that pixel block look. The cure is to have a high res pic.

Good Luck

 
tnx vb5prgrmr for the help...
What i did with my program was to set the height and width property and I got what i really wanted with my program. Thank you very much.

Jeffrey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top