Private Sub SetPicture(ByVal imgSrc As Bitmap, ByVal target As PictureBox)
Dim imgDest As Bitmap = New Bitmap(target.ClientSize.Width, target.ClientSize.Height)
Dim source_aspect, dest_aspect, k_aspect, K As Double
source_aspect = imgSrc.Width / imgSrc.Height
dest_aspect = imgDest.Width / imgSrc.Height
k_aspect = dest_aspect / source_aspect
If (k_aspect > 1) Then
K = imgSrc.Height / imgDest.Height
Else
K = imgSrc.Width / imgDest.Width
End If
Dim x_new, y_new, w_new, h_new As Integer
w_new = CInt(imgSrc.Width / K)
h_new = CInt(imgSrc.Height / K)
x_new = CInt(imgDest.Width / 2 - w_new / 2)
y_new = CInt(imgDest.Height / 2 - h_new / 2)
Dim g As Graphics = Graphics.FromImage(imgDest)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgSrc, New Rectangle(x_new, y_new, w_new, h_new))
g.Dispose()
target.Image = imgDest
End Sub
Dim ImageToDisplay As Bitmap = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData("ImageLocation")))
SetPicture(ImageToDisplay, PicBoxProducts)
Προσαρμογή εικόνας στο PictureBox
Δημοσιεύθηκε στην .net. Αποθηκεύστε τον μόνιμο σύνδεσμο.