Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

REDIM PROPORTIONNEL D’UN FICHIER IMAGE.


Information sur la source

Catégorie :Graphique Source .NET ( DotNet ) Niveau : Débutant Date de création : 04/11/2004 Vu : 5 229

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

Description

Voici une source qui prend un fichier image, qui change la propriété Width du fichier et garde les proportion sur Height.

Le resultat est enregistré dans un autre fichier.

PathOrigine -> Fichier d’origine
PathDestination -> Fichier de  destination
Int_Width -> Width en pixels

 

Source

  • 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

Conclusion

Return string.Empty si tout est bon, si non return message d'erreur

Merci de me signaler tt bug
 

Commentaires et avis

signaler à un administrateur
Commentaire de cboulas le 11/07/2006 10:37:50

Génial exactement ce que j'avais besoin, et surtout c'est que l'on ne perd pas de la qualité d'image comme avec la fonction GetThumbnails

signaler à un administrateur
Commentaire de cboulas le 11/07/2006 10:43:29

Génial exactement ce que j'avais besoin, et surtout c'est que l'on ne perd pas de la qualité d'image comme avec la fonction GetThumbnails

signaler à un administrateur
Commentaire de jmenfous le 11/07/2006 10:49:58

Merci ;-) ca fait plaisir d'aider.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Janvier 2009
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,484 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.