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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading resizing and save picture

Status
Not open for further replies.

dominiopt

Technical User
Sep 10, 2001
75
PT
I guys can someone help me on this.

1.Why this code still given me this error ?
Run error 438 (object doesn't support this property or method)

2.I have also problems in LoadPicture uses Twips and SavePicture
uses Pixels, how can i load pic also in Pixels ?


Dim pic As Picture
Dim picWidth, picHeight As Long

'get pic width and height

Set pic = LoadPicture(filePath & "\" & Filename)
picWidth = pic.Width
picHeight = pic.Height

'make pic new width and height

If picWidth > picHeight Then
pic.Width = 100 <------------ error here
pic.Height = 100 * (picHeight / picWidth)
End If

'save mirror pic

SavePicture pic, App.Path & &quot;\Temp\&quot; & Filename

Thanks
Fernando
 
&quot;Dim picWidth, picHeight As Long&quot;

picWidth is a Variant

should be:
Dim picWidth As Long
Dim picHeight As Long

&quot;pic.Width = 100 <------------ error here&quot;

dont know yet !

®od
 
Ahem - the problem is that the Width and Height properties of Picture (really just an alias for StdPicture, which is an implmentation of the IPicture interface) are read-only, although this is not documented particularly well.

So you can't resize a Picture the way you are trying to.

Also, LoadPicture doesn't use any units at all. However it creates a Picture object, which is actually measured in OLE_XSIZE_HIMETRIC for width and OLE_YSIZE_HIMETRIC for height.

HiMetric (each unit is 0.01 millimeter) isn't a ScaleMode that you can pick in the IDE, although you CAN work with it progammatically, as in this example (you'll need a form with on PictureBox, who's Visible property is set to false, and a Command button):
[tt]
Option Explicit
Private Const filepath = &quot;c:&quot; 'Just my choices
Private Const Filename = &quot;tinyhorde.jpg&quot;

Private Sub Command1_Click()
Dim myPic As Picture ' Or StdPicture or IPicture

' Ok, scale the picture box to match himetric units of StdPicture
Picture1.ScaleX Picture1.Width, Picture1.ScaleMode, vbHimetric
Picture1.ScaleY Picture1.Height, Picture1.ScaleMode, vbHimetric
Picture1.AutoRedraw = True
Picture1.BorderStyle = 0

Set myPic = LoadPicture(filepath & &quot;\&quot; & Filename) If myPic.Width > 1000 Then '100 is pretty small in HiMetric terms, so I'm arbitarily selecting 1000
Picture1.Width = 1000
Picture1.Height = 1000 * myPic.Height / myPic.Width
Picture1.PaintPicture myPic, 0, 0, 1000, 1000 * myPic.Height / myPic.Width
End If

SavePicture Picture1.Image, App.Path & &quot;\Temp\&quot; & Filename

End Sub
[/tt]
Note that this is just one way of resizing an image

 
Strongm great explanation, clear as watter mountain.
Many thanks
 
Hi Strongm, sorry come back with this subject again but i need extra help.
Your code works just fine, however i'am trying put picture centered in picture space available in this case 2000 x 2000.

Picture1.PaintPicture Pic, 0, (2000 - Picture1.Height) / 2, 2000, (2000 * Pic.Height / Pic.Width) - (2000 - Picture1.Height)

According your code i supose must be like this, but i didn't reach good results. Another question (i didn't reach there) for cleanning previous pic extra &quot;image&quot; must do picture1.refresh ?

Thanks again
Fernando
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top