Solved

Problem using Printer.PaintPicture with wmf files

Posted on 2010-09-21
8
638 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 33732811

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
ID: 33734182
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
ID: 33734518
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthedark
ID: 33734589
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
ID: 33736721
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
ID: 33799382
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 101

Expert Comment

by:mlmcc
ID: 34904991
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been sent a PowerPoint presentation file and wondered why it filled your mailbox? Or have you ever sent a PowerPoint presentation by email and received complaints about the size? Or have you ever created a PowerPoint presentation and t…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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