begin process at 2012 02 16 14:00:02
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Graphique

 > REDIM PROPORTIONNEL D’UN FICHIER IMAGE.

REDIM PROPORTIONNEL D’UN FICHIER IMAGE.


 Information sur la source

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

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Graphique Source .NET ( DotNet ) Niveau :Débutant Date de création :04/11/2004 Vu :6 231

Auteur : jmenfous

Ecrire un message privé
Site perso
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


 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) PROGRAMME TV A PARTIR DE FICHIERS XMLTV EN .NET2
Source avec Zip Source avec une capture Source .NET (Dotnet) PROGRAMMES TV À PARTIR DE FICHIERS XMLTV

 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) VB10 - CRÉER VOS PROPRES CALQUES SUR UNE IMAGE par Duke49
Source avec Zip Source avec une capture Source .NET (Dotnet) CREER UN GIF ANIMÉ par Le Pivert
Source avec une capture GRAPH PHP COURBE DE CHARGE par s.defaye
Source avec Zip Source avec une capture BOULE DE CRISTAL par BLUEBIBUBBLE
VB6 - DÉPLACEMENT D'UN CONTRÔLE SUR UN SEGMENT DE DROITE DÉL... par ucfoutu

Commentaires et avis

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

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

Commentaire de jmenfous le 11/07/2006 10:49:58

Merci ;-) ca fait plaisir d'aider.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), 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

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,936 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales