私は次のコードを持っています:
Private Function SizeLogo(ByVal logoBytes As Byte()) As Byte()
Using originalMemStream As MemoryStream = New MemoryStream(logoBytes),
originalImage As System.Drawing.Image = System.Drawing.Image.FromStream(originalMemStream)
Dim width As Integer = originalImage.Width
Dim height As Integer = originalImage.Height
Dim targetWidth As Integer = 300
Dim targetHeight As Integer = 200
Dim newHeight As Integer = 0
Dim newWidth As Integer = 0
Using oBitmap As New Bitmap(300, 200)
Using oGraphic As Graphics = Graphics.FromImage(oBitmap)
Using oBrush As New SolidBrush(Color.White)
oGraphic.FillRectangle(oBrush, 0, 0, targetWidth, targetHeight)
End Using
Using oProduto As System.Drawing.Image = Drawing.Image.FromStream(originalMemStream)
Dim targetRatio As Decimal = CDec(targetWidth) / CDec(targetHeight)
Dim imageRatio As Decimal = CDec(width) / CDec(height)
If targetRatio > imageRatio Then
newHeight = targetHeight
newWidth = CInt(Math.Floor(imageRatio * CDec(targetHeight)))
Else
newHeight = CInt(Math.Floor(CDec(targetWidth) / imageRatio))
newWidth = targetWidth
End If
If newWidth > targetWidth Then newWidth = targetWidth
If newHeight > targetHeight Then newHeight = targetHeight
oGraphic.DrawImage(oProduto, 0, 0, newWidth, newHeight)
**Using thumbImage As Drawing.Image = oGraphic. .GetThumbnailImage(targetWidth, targetHeight, Nothing, IntPtr.Zero),
outMemStream As MemoryStream = New MemoryStream()
thumbImage.Save(outMemStream, ImageFormat.Jpeg)
Return outMemStream.ToArray()
End Using**
End Using
End Using
End Using
End Using
End Function
私がやろうとしているのは
- 300幅と200高さの白いビットマップを作成します
- センターにアップロードされた画像を描画して中央に配置
私の問題は、作成した画像を保存できないことです。これは変換の問題ですか?失敗していると思うコードを強調表示しました。