Public Function PicResizeByPercent(ByVal SourceImage As String, ByVal Percent _
As Short) As Bitmap
Dim InputBitmap As New Bitmap(SourceImage)
Dim NewWidth As Integer = ((Percent / 100) * InputBitmap.Width)
Dim SizeFactor As Decimal = NewWidth / InputBitmap.Width
Dim NewHeigth As Integer = SizeFactor * InputBitmap.Height
Dim OutputBitmap As New Bitmap(System.Drawing.Image.FromFile( _
SourceImage), NewWidth, NewHeigth)
PicResizeByPercent = OutputBitmap
InputBitmap.Dispose()
OutputBitmap.Dispose()
End Function Public Function PicResizeByWidth(ByVal SourceImage As String, ByVal _
NewWidth As Integer) As Bitmap
Dim InputBitmap As New Bitmap(SourceImage)
Dim SizeFactor As Decimal = NewWidth / InputBitmap.Width
Dim NewHeigth As Integer = SizeFactor * InputBitmap.Height
Dim OutputBitmap As New Bitmap(System.Drawing.Image.FromFile( _
SourceImage), NewWidth, NewHeigth)
PicResizeByWidth = OutputBitmap
InputBitmap.Dispose()
OutputBitmap.Dispose()
End Function Public Sub AutosizeImage(ByVal ImagePath As String, ByVal picBox As _
PictureBox, Optional ByVal pSizeMode As PictureBoxSizeMode = _
PictureBoxSizeMode.CenterImage)
Try
picBox.Image = Nothing
picBox.SizeMode = pSizeMode
If System.IO.File.Exists(ImagePath) Then
Dim imgOrg As Bitmap
Dim imgShow As Bitmap
Dim g As Graphics
Dim divideBy, divideByH, divideByW As Double
imgOrg = DirectCast(Bitmap.FromFile(ImagePath), Bitmap)
divideByW = imgOrg.Width / picBox.Width
divideByH = imgOrg.Height / picBox.Height
If divideByW > 1 Or divideByH > 1 Then
If divideByW > divideByH Then
divideBy = divideByW
Else
divideBy = divideByH
End If
imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), _
CInt(CDbl(imgOrg.Height) / divideBy))
imgShow.SetResolution(imgOrg.HorizontalResolution, _
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode = _
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl( _
imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / _
divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, _
GraphicsUnit.Pixel)
g.Dispose()
Else
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
imgShow.SetResolution(imgOrg.HorizontalResolution, _
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode = _
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, _
imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _
GraphicsUnit.Pixel)
g.Dispose()
End If
imgOrg.Dispose()
picBox.Image = imgShow
Else
picBox.Image = Nothing
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub ''' <summary>
''' Diese Funktion Komprimiert ein JPEG Bild und speichert dieses als neues
' Bild ab
''' </summary>
''' <param name="Image">Das Bild welches komprimiert werden soll</param>
''' <param name="OutPutFile">Der Pfad des neuen komprimierten Bilds</param>
''' <param name="Qualitiy">Die Qualitätseinstellung 0-100</param>
Public Sub JPEGCompression(ByVal Image As Image, ByVal OutPutFile As _
String, ByVal Qualitiy As Integer)
Dim ImageCodecs() As ImageCodecInfo
Dim ImageParameters As EncoderParameters
ImageCodecs = ImageCodecInfo.GetImageEncoders()
ImageParameters = New EncoderParameters(1)
ImageParameters.Param(0) = New EncoderParameter( _
System.Drawing.Imaging.Encoder.Quality, Qualitiy)
Image.Save(OutPutFile, ImageCodecs(1), ImageParameters)
End Sub Villeicht hilft dir das weiter...
mfgMeik MillerMein beste Code:If then  |