以下に示すように、VB.netを使用して画像のサイズを変更した後の白い背景。いくつかの値を変更しようとしましたが、失敗しました。
Dim FileToResize As String = Server.MapPath("~/images/" & filename & FileUpload1.FileName)
Using originalBitmap As Bitmap = Bitmap.FromFile(FileToResize, True), newbmp As Bitmap = New Bitmap(200, 200)
Dim WidthVsHeightRatio = CDec(originalBitmap.Width) / CDec(originalBitmap.Height)
Using newg As Graphics = Graphics.FromImage(newbmp)
newg.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
newg.Clear(Color.White)
If WidthVsHeightRatio = 1D Then
newg.DrawImage(originalBitmap, 0, 0, 200, 200)
newg.Save()
ElseIf WidthVsHeightRatio < 1D Then 'Image is taller than wider
newg.DrawImage(originalBitmap, New RectangleF(New PointF((100 - (200 * WidthVsHeightRatio) / 2), 0), New SizeF(200 * WidthVsHeightRatio, 200.0F)))
newg.Save()
Else 'Image is wider than taller
Dim inverse As Double = Math.Pow(WidthVsHeightRatio, -1)
newg.DrawImage(originalBitmap, New RectangleF(New PointF(0, 100 - ((200 * inverse) / 2)), New SizeF(200.0F, 200 * inverse)))
newg.Save()
End If
End Using
newbmp.Save(Server.MapPath("~/images/" & "_th_" & filename & FileUpload1.FileName), System.Drawing.Imaging.ImageFormat.Jpeg)
NewsItem.ImageLink = filename & FileUpload1.FileName
NewsItem.smallimage = "_th_" & filename & FileUpload1.FileName
End Using