PaintPicture Method

Purpose

Draws the contents of a graphics file (.bmp, .wmf, .emf, .cur, .ico, or .dib) on a Form or Printer.

Syntax

[object.]PaintPicture pict, x1, y1[, w1, h1, x2, y2, w2, h2, opcode]

x1, y1, w1, h1, x2, y2, w2, h2: floating-point exp
opcode: iexp
pict: Picture Object

Description

object. - The name of the Form or Printer object where the picture is to be placed. This argument is optional. If it's omitted, the form with the focus (Me) is assumed.

pict - The Picture object to paint.

x1, y1 - Single-precision values indicating the destination coordinates (in other words, the location on the destination object where the top-left corner of the image is to be drawn). The ScaleMode property of the object determines the unit of measure used.

w1, h1 - Single-precision values indicating the destination width and height of the picture, using units specified by the ScaleMode property of the destination object. If the destination width and/or height is larger or smaller than the source width (w2) or height (h2), the picture is stretched or compressed to fit. These arguments are optional; if you omit them, the source width (w1) and height (h1) are used with no stretching or compression.

x2, y2 - Single-precision values indicating the source coordinates of the region in the source object that is to be copied (in units specified by the source object's ScaleMode property). These arguments are optional; if you omit them, 0 is assumed (indicating the top-left corner of the source image).

w2, h2 - Single-precision values indicating the width and height of the region within the source that is to be copied (in units specified by the source object's ScaleMode property). These arguments are optional; if you omit them, the entire source width and height are used.

opcode - A type Long value that defines the bit-wise operation that is performed between the pixels of the source picture and the pixels of any existing image on the destination. This argument, which is optional, is useful only with bitmaps. If you omit the argument, the source is copied onto the destination, replacing anything that is there.

For a complete list of bit-wise operator constants, see the BitBlt RasterOp Constants

PaintPicture without an object identifier is executed on the current output device (Me or OutPut =)

Note 1: The source parameters are only in Himetric units if the opcode parameter isn’t used; if the opcode parameter is specified, the source parameters are in pixels.

Note 2: A dpi-aware app should use the variant that explicitly uses the opcode parameter.

Example

OpenW # 1 : AutoRedraw = 1

Local pic As Picture, h As Handle, n As Int32

For n = 1 To 601 Step 50

Line 0, n, 601, n

Line n, 0, n, 601

Next n

Set pic = Win_1.PrintPicture

Dlg Print Win_1, 0, h

If h <> 0

Local Int32 ht = HimetsToPixelY(pic.Height), wd = HimetsToPixelX(pic.Width)

SetPrinterHDC h

Output = Printer

'Lprint ""; // Causes an error with some printers if used to force start the print process

Printer.StartDoc "test"

Printer.StartPage

PaintPicture pic, 0, 0, wd * 2, ht * 2

Printer.EndPage

Printer.EndDoc

Output = Me

EndIf

This prints a hardcopy of a form (Me) as small as a stamp on the printer, but you can scale it by changing the wd*2 and ht*2 parameters as you wish.

See Also

Bitblt

{Created by Sjouke Hamstra; Last updated: 28/05/2022 by James Gaite; Other Contributors: Jean-Marie Melanson}