Problem using Printer.PaintPicture with wmf files

We create our wmf files using PowerPoint vbscript (Slide.Export to wmf). In particular these slides may contain pictures (clipart) which extend beyond the slide's frame. In other words, a portion of the clipart is within the slide’s borders -- the rest is outside of the frame but viewable in PowerPoint’s editor.

When opening these wmf files using Paint, Windows Picture and Fax Viewer, or Microsoft Office Picture Manager, the wmf is displayed correctly -- all the content within the slide’s frame is visble – any content outside the frame is obscured.

Now, in our standalone VB6 Windows form application, we load the wmf files using the following code (Image1 is an Image component within our form)

Image1.Picture = LoadPicture("c:\sample.wmf")

When we attempt print the image, using the following code

Printer.PaintPicture Image1.Picture, 0, 0 (Printer could be pointing to any printer)

the printout shows all of the content, including the portion of the pictures which were supposed to be obscured. I had attempted to use PictureBox component  instead of an Image component but Printer.PaintPicture still prints all of the content.

I need to print just what’s inside of the slide’s frame. Any thoughts?

Who is Participating?
mic138Connect With a Mentor Author Commented:
I am going to forego obtaining an answer since we have established a workaround with the user.

It seems as if PowerPoint (PW) does not obscure portions of an image out side of the slide's frame when the image is manipulated (in our case rotated) within the PW editor. If you manipulate the image, using graphics software, before pasting (straddling the image over the slide's border), then the portion of the image outside of the slide is obscured.

The documentation for paintpicture is a touch scanty when it comes to the implantation of picture cropping.

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

1) You need to set x1 & y1 as the position on the page where you want the top left of the picture to be.
2) Width1 & Height1 are the size of the picture that you want on your page.
Setting these values must be done in proportion to the width/height of the source image in order to preserve the aspect ratio of the image.
3) X2 & Y2 you set to the left/top position on the source image that you want. So these are affectively your crop left and crop top settings.
4)  width2 & height2 specify the size of the area from point x2,y2 that you want to select from the source image.
So to use copping from right and bottom is a simple matter of calculation.

Tip 1 test the output to the screen before testing the print so you don;t waste a lot of ink & paper.

Code Sample to follow

Good luck and hope this helps :~)

' Sample assumes picture boxes picture1 & picture2 and chkLandscape check box

Dim sFile As String

' this example assumes that your picture boxes & printer are set to twips

' the the source image
sFile = "c:\$WebZone\WebSite\Newsletters\globe.wmf"
Picture2.AutoRedraw = True ' the source image will acquire correct sizes
Picture2.AutoSize = True 

Picture1.AutoRedraw = True ' so you can see changes

Set Picture2.Picture = LoadPicture(sFile)

Dim sngSourceWidth As Single
Dim sngSourceHeight As Single

' Get the width & height of source of the image
sngSourceWidth = Picture2.ScaleWidth
sngSourceHeight = Picture2.ScaleHeight

' Set a value depending on metric centimeters or inches for cropping conversion
Dim TWIPS As Single
Dim YourScaleMode As String

YourScaleMode = "M" ' today we will work in cm

If YourScaleMode = "M" Then
    TWIPS = 567 ' metric
    TWIPS = 1440 ' inches
End If

' Connect to the destination of the picture
Dim objOutput As Object
Dim bTest As Boolean

bTest = True
If bTest Then
    Set objOutput = Picture1
    Set objOutput = Printer
    Printer.ScaleMode = vbTwips
    If cnkLandscape.Value = 1 Then ' check box to select landscape
        objOutput.Orientation = 2
        objOutput.Orientation = 1
    End If
End If

' Set output margins

Dim LeftMargin As Single
Dim RightMargin As Single
Dim TopMargin As Single
Dim BottomMargin As Single

' set margin postitions at 1 cm
LeftMargin = TWIPS * 1 ' Set position 1 cm from left
RightMargin = TWIPS * 1 ' set position 1 CM from top
TopMargin = TWIPS * 1
BottomMargin = TWIPS * 1

' set destination image size
Dim X1 As Single
Dim Y1 As Single
Dim W1 As Single
Dim H1 As Single

X1 = LeftMargin
Y1 = TopMargin

' now set Source cropping regions
Dim CropLeft As Single
Dim CropTop As Single
Dim CropRight As Single
Dim CropBottom As Single

CropLeft = TWIPS * 0.1 'val(txtCtopLeft) set these form a textbox or something
CropRight = TWIPS * 0.1
CropTop = TWIPS * 0.1
CropBottom = TWIPS * 0.1

' set source image size
Dim X2 As Single
Dim Y2 As Single
Dim W2 As Single
Dim H2 As Single

X2 = CropLeft
Y2 = CropTop
W2 = sngSourceWidth - CropLeft - CropRight
H2 = sngSourceHeight - CropTop - CropBottom

' Calculate Aspect Ratio using formula

Dim AspectRatio As Single
AspectRatio = H2 / W2

' calculate output available width
W1 = objOutput.ScaleWidth - LeftMargin - RightMargin
H1 = AspectRatio * W1

' make sure that the image will fit on the page
Dim AvailableHeight As Single
AvailableHeight = objOutput.ScaleHeight - TopMargin - BottomMargin

If H1 > AvailableHeight Then
    H1 = AvailableHeight
    W1 = (H1 * W2) / H2
End If

If X2 < 0 Or Y2 < 0 Or W2 < 0 Or H2 < 0 Then
    MsgBox "You have over cropped your image dummy!"
End If

' finally we are now ready to print the image
objOutput.PaintPicture Picture2.Image, X1, Y1, W1, H1, X2, Y2, W2, H2, vbSrcCopy

Open in new window

mic138Author Commented:
I thought of cropping the image as well by supplying values for  x2, y2, width2, height2. However, there is no way of determining these values considering, in order to crop, I would need to know the width and height of the slide's frame relative to overall width and height of the entire image. That information is not available within our VB6 application once the wmf is loaded into an Image object using LoadPicture.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

If the picturebox.autosize = true, the image will autosize when loaded so you get to know image width & height.

I presume that there is some kind of border around the slides. If the slide border is white, or a common format, if would be possible to calculate automatically using some crafty magic with the image pixels.
Perhaps you could upload an image and I could give you some code that you calculate the real image x2,y2,w2 & h2
mic138Author Commented:
The file has been uploaded. Please note, EE does not allow attachments of wmf file types, Hence, although the attached file is a wmf file, you will have to be rename it by replacing the word "dot" with a period ".".

Thanks for all of your help so far.
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.