- Private Function Redim_Image(ByVal vStr_PathOrigine As String, ByVal vStr_PathDestination As String, ByVal vInt_Width As Integer) As String
- Try
- 'test si fichier existe
- If Not IO.File.Exists(vStr_PathOrigine) Then
- Return "Le fichier [" & vStr_PathOrigine & "] n'existe pas."
- Exit Function
- End If
- 'test le type image
- Dim F As New IO.FileInfo(vStr_PathOrigine)
-
- Select Case F.Extension.ToLower
- Case ".gif", ".jpg", "jpeg", ".bmp"
- 'ras c bon
- Case Else
- Return "Les fichier image d'origne doit avoir l'extension [.gif], [.jpg], [jpeg] ou [.bmp]"
- Exit Function
- End Select
- F = Nothing
-
- 'effacer destination
- If IO.File.Exists(vStr_PathDestination) Then IO.File.Delete(vStr_PathDestination)
-
- 'charge image d'origine
- Dim Img As Drawing.Image
- Img = Drawing.Image.FromFile(vStr_PathOrigine)
-
- Dim Int_Height As Integer = vInt_Width * Img.Height / Img.Width
-
- Dim B As New Bitmap(vInt_Width, Int_Height)
- Dim G As Graphics = Graphics.FromImage(B)
- G.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
- G.DrawImage(Img, 0, 0, vInt_Width, Int_Height)
- B.Save(vStr_PathDestination, Drawing.Imaging.ImageFormat.Jpeg)
-
- Return String.Empty
- Catch ex As Exception
- Return ex.Message
- End Try
-
- End Function
Private Function Redim_Image(ByVal vStr_PathOrigine As String, ByVal vStr_PathDestination As String, ByVal vInt_Width As Integer) As String
Try
'test si fichier existe
If Not IO.File.Exists(vStr_PathOrigine) Then
Return "Le fichier [" & vStr_PathOrigine & "] n'existe pas."
Exit Function
End If
'test le type image
Dim F As New IO.FileInfo(vStr_PathOrigine)
Select Case F.Extension.ToLower
Case ".gif", ".jpg", "jpeg", ".bmp"
'ras c bon
Case Else
Return "Les fichier image d'origne doit avoir l'extension [.gif], [.jpg], [jpeg] ou [.bmp]"
Exit Function
End Select
F = Nothing
'effacer destination
If IO.File.Exists(vStr_PathDestination) Then IO.File.Delete(vStr_PathDestination)
'charge image d'origine
Dim Img As Drawing.Image
Img = Drawing.Image.FromFile(vStr_PathOrigine)
Dim Int_Height As Integer = vInt_Width * Img.Height / Img.Width
Dim B As New Bitmap(vInt_Width, Int_Height)
Dim G As Graphics = Graphics.FromImage(B)
G.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
G.DrawImage(Img, 0, 0, vInt_Width, Int_Height)
B.Save(vStr_PathDestination, Drawing.Imaging.ImageFormat.Jpeg)
Return String.Empty
Catch ex As Exception
Return ex.Message
End Try
End Function