Solved

Problem using Printer.PaintPicture with wmf files

Posted on 2010-09-21
8
619 Views
Last Modified: 2013-12-25
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?

thx
0
Comment
Question by:mic138
  • 3
  • 3
8 Comments
 
LVL 17

Expert Comment

by:inthedark
Comment Utility

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

Else

    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

Else

    Set objOutput = Printer

    Printer.ScaleMode = vbTwips

    If cnkLandscape.Value = 1 Then ' check box to select landscape

        objOutput.Orientation = 2

    Else

        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

' DH/DW = SH/SW





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

0
 

Author Comment

by:mic138
Comment Utility
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.
0
 
LVL 17

Expert Comment

by:inthedark
Comment Utility
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.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 17

Expert Comment

by:inthedark
Comment Utility
Perhaps you could upload an image and I could give you some code that you calculate the real image x2,y2,w2 & h2
0
 

Author Comment

by:mic138
Comment Utility
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.
n01dotwmf
0
 

Accepted Solution

by:
mic138 earned 0 total points
Comment Utility
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.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article shows how to simulate drawing numbers or names from a hat or bag using vba in PowerPoint and prevents duplicate items being selected. It’s not difficult to choose a (semi) random number in vba. The RND function returns a decimal numb…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now