Já úspěšně používám tohle:
''' <summary>
''' Vytvoří a udělá náhled obrázku
''' </summary>
Friend Shared Function CreateThumbnail(ByVal id As Integer) As Size
Dim orig As New Bitmap(GetImagePhysicalPath(id))
'vytvořit náhled
Dim b As New Bitmap(Uraeus.Config.PhotoGallery.ThumbnailWidth, Uraeus.Config.PhotoGallery.ThumbnailHeight)
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(Color.White)
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Dim thumbSize As Size = GetImageSize(orig.Width, orig.Height, b.Width, b.Height)
If thumbSize.IsEmpty Then thumbSize = New Size(orig.Width, orig.Height)
g.DrawImage(orig, CInt((b.Width - thumbSize.Width) / 2), CInt((b.Height - thumbSize.Height) / 2), thumbSize.Width, thumbSize.Height)
SaveImage(b, GetThumbnailPhysicalPath(id))
g.Dispose()
b.Dispose()
End Function
''' <summary>
''' Uloží obrázek ve formátu JPEG ve vysoké kvalitě
''' </summary>
Public Shared Sub SaveImage(ByVal b As Bitmap, ByVal filename As String)
Dim params As New EncoderParameters(1) : params.Param(0) = New EncoderParameter(Encoder.Quality, 92)
b.Save(filename, ImageCodecInfo.GetImageEncoders().First(Function(c) c.MimeType = "image/jpeg"), params)
End Sub
|