Main Page | Report this Page
.NET DotNet Forum Index  »  VB.NET Forum (Visual Basic .NET)  »  How to convert image file to fixed size bmp format?...
Page 1 of 1    

How to convert image file to fixed size bmp format?...

Author Message
yxq...
Posted: Wed Nov 04, 2009 8:34 pm
Guest
I want to convert an image file(JPG...) to a fixed size bmp format image,
and the converted bmp image will not be deformed, can anyone give a sample?
Thank you.
 
yxq...
Posted: Wed Nov 04, 2009 10:49 pm
Guest
The code below work well.
////////////////////////////////////////////////////////////////////////////////
Public Function GetRglThumbnail(ByVal imgSource As Image,
ByVal itWidth As Integer, ByVal itHeight As Integer) As
Image
Dim sngScale As Single
If itWidth / itHeight < imgSource.Width /
imgSource.Height Then
sngScale = Convert.ToSingle(itWidth /
imgSource.Width)
Else
sngScale = Convert.ToSingle(itHeight /
imgSource.Height)
End If
Dim g As Graphics, imgReturn As New
Bitmap(itWidth, itHeight)
Try
g = Graphics.FromImage(imgReturn)
g.Clear(Color.White)
g.TranslateTransform(Convert.ToSingle(itWidth) / 2,
Convert.ToSingle(itHeight) / 2)
g.ScaleTransform(sngScale, sngScale)
g.DrawImage(imgSource,
Convert.ToInt32(-imgSource.Width / 2),
Convert.ToInt32(-imgSource.Height / 2), imgSource.Width,
imgSource.Height)
Return imgReturn
Catch ex As Exception
Finally
If Not (g Is Nothing) Then g.Dispose()
End Try
End Function

"yxq" <gayxq at (no spam) 163.net> 写入消息新闻:%23pZ3hgbXKHA.3612 at (no spam) TK2MSFTNGP02.phx.gbl...
Quote:
I want to convert an image file(JPG...) to a fixed size bmp format image,
and the converted bmp image will not be deformed, can anyone give a sample?
Thank you.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sun Nov 29, 2009 6:09 pm