Scale Image

shers

Well-known member
Joined
Aug 12, 2007
Messages
86
Programming Experience
1-3
I drew an image in a picturebox with the image height as picturebox height and image width as picturebox width. The image is placed somewhere on the center of the picturebox. My intention is to scale the image to fit to the picturebox. How do I do this please?

Thanks
 
Why don't I see anything in the picture box for this code?

x = 266
y = 14
width = 134
height = -14
g = Graphics.FromImage(bit)
g.DrawRectangle(myPen, x, 0 - (y + height), width, height)
g.DrawString("Test", New Font("Tahoma", 8), Brushes.Black, x, y)
myPen.Dispose()
g.Dispose()

Thanks
 
I know this is an older post but here is a function I wrote to scale an image to fit into a picture box


Public Function ScaleImage(ByVal OldImage As Image, ByVal TargetHeight As Integer, ByVal TargetWidth As Integer) As System.Drawing.Image

Dim NewHeight As Integer = TargetHeight
Dim NewWidth As Integer = NewHeight / OldImage.Height * OldImage.Width


If NewWidth > TargetWidth Then
NewWidth = TargetWidth
NewHeight = NewWidth / OldImage.Width * OldImage.Height
Else
NewHeight = TargetHeight
NewWidth = NewHeight / OldImage.Height * OldImage.Width
End If

Return New Bitmap(OldImage, NewWidth, NewHeight)

End Function


InkedGFX
 
Back
Top