ArgumentException - Le paramètre n'est pas valide
Bonjour, j'utilise ce code pour redimensionner une image et lui appliquer un filtre d'interpolation mais j'obtiens cette erreur sur chaque paramètre de pixelformat que je définis au moment de la création du BitMap.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
Private Function ScaleByPercent(ByVal Img As Image, ByVal Percent As Integer) As Image
Dim nPercent As VariantType = Percent / 100
Dim sourceWidth As Integer = Img.Width
Dim sourceHeight As Integer = Img.Height
Dim sourceX As Integer = 0
Dim sourceY As Integer = 0
Dim destWidth As Integer = (sourceWidth * nPercent)
Dim destHeight As Integer = (sourceWidth * nPercent)
Dim destX As Integer = 0
Dim destY As Integer = 0
Dim bm As Bitmap = New Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb)
bm.SetResolution(Img.HorizontalResolution, Img.VerticalResolution)
Dim gr As Graphics = Graphics.FromImage(bm)
gr.InterpolationMode = InterpolationMode.HighQualityBilinear
gr.DrawImage(Img, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)
gr.Dispose()
Return bm
End Function |
Merci de votre aide