[RESOLVED] Image Resize and save problem
hi,
i have a problem with image.
i have loaded an image in the
Code:
Image1.Picture = loadpicture("c:\abc.jpg")
but when i change its size height and width by
Code:
Image1.height=200
image1.width=2000
and save it by its new size by this code
the image size is not changes to its new size.
how i can do it?
i want to save the picture with its new size i have set by my code
Re: Image Resize and save problem
The picture loaded always stays the same. It is loaded into a bitmap and paintet to the image controls "screen" whenever it is refreshed.
If the image control is resized, and stretch is on, then the image from the bitmap is painted bigger or smaller, but the bitmap itself remains unchanged.
Therefore on the first view your task is not too trivial.
I'd say there could be some API calls which you might use...
I hope one of the graphic gurus is taking over :)
Re: Image Resize and save problem
You can use the PaintPicture member of PictureBox to resize the image and save it to a file
Code:
Dim pic As StdPicture
Set pic = LoadPicture("<SOURCE FILENAME>")
With Picture1
.AutoRedraw = True
Call .PaintPicture(pic, 0, 0, .ScaleX(200, vbPixels, .ScaleMode), .ScaleY(200, vbPixels, .ScaleMode))
.AutoRedraw = False
Call SavePicture(.Image, "<DESTINATION FILENAME>")
End With
Hope it will help you
Re: Image Resize and save problem
I have to make changes to the code. The .image returns only the part within the rect of the picturebox so we have to resize the control to our desired picture size. Here's my code that works with any scalemode of the picturebox. It also takes into account if the picturebox has a border.
Code:
Dim pic As StdPicture
Const sizeX As Integer = 200, sizeY As Integer = 200
Set pic = LoadPicture("<SOURCE FILENAME HERE>")
With Picture1
.Width = (sizeX * Screen.TwipsPerPixelX) + .Width - .ScaleX(.ScaleWidth, .ScaleMode, vbTwips)
.Height = (sizeY * Screen.TwipsPerPixelY) + .Height - .ScaleY(.ScaleHeight, .ScaleMode, vbTwips)
.AutoRedraw = True
.Cls
Call .PaintPicture(pic, 0, 0, .ScaleWidth, .ScaleHeight)
.AutoRedraw = False
Call SavePicture(.Image, "<DESTINATION FILENAME HERE>")
End With
You can make the picturebox invisible so users won't see it
Re: Image Resize and save problem
And even without any extra control because they are made on the go.
the only thing you need is a form thats called frmMain or if you wish you can change that to another name
Code:
Public Function Create_Thumb(sImagePath As String,sDestPath as string, Optional lPixWidth As Long = 95, Optional lPixHeight As Long = 95) As String
Dim iTwipHeight As Long, iTwipWidth As Long
iTwipWidth = ConvertPixelsToTwips(lPixWidth)
iTwipHeight = ConvertPixelsToTwips(lPixHeight, 1)
Dim picTemp As Control, picImage As Control
Set picTemp = frmMain.Controls.Add("vb.picturebox", "picTemp", frmMain)
Set picImage = frmMain.Controls.Add("vb.picturebox", "picImage", frmMain)
picTemp.AutoSize = True
picImage.AutoSize = True
picImage.AutoRedraw = True
picTemp.Picture = LoadPicture(sImagePath)
picImage.Picture = LoadPicture()
If picTemp.Width > iTwipWidth Or picTemp.Height > iTwipHeight Then
Dim cRatio As Currency
picImage.Width = iTwipWidth
picImage.Height = iTwipHeight
If picTemp.Width > picTemp.Height Then
cRatio = picTemp.Width / picImage.Width
Else
cRatio = picTemp.Height / picImage.Height
End If
picImage.Width = picTemp.Width / cRatio
picImage.Height = picTemp.Height / cRatio
picImage.PaintPicture picTemp.Picture, 0, 0, picImage.Width, picImage.Height
picImage.Picture = picImage.Image
Else
picImage.Width = picTemp.Width
picImage.Height = picTemp.Height
picImage.Picture = picTemp.Picture
End If
picImage.Refresh
picTemp.Picture = LoadPicture
frmMain.Controls.Remove "picTemp"
Call SavePicture(picimage.picture,sDestPath)
'-clear data
ClearData:
picImage.Picture = LoadPicture
frmMain.Controls.Remove "picImage"
End Function
Re: Image Resize and save problem
you could also look at the Crop and Zoom project...
Theres plenty on code there to help ..
Gremmy...
Re: Image Resize and save problem
Is there any way short of 3rd party addin to save the image as a Jpeg?
1 Attachment(s)
Re: Image Resize and save problem
Re: Image Resize and save problem
Free will be just fine :)
Thanks
Re: Image Resize and save problem