Accueil > > > REDIM PROPORTIONNEL D’UN FICHIER IMAGE.
REDIM PROPORTIONNEL D’UN FICHIER IMAGE.
Information sur la source
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
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[HTML5] SLIDES ET DéMOS : AUTOUR DU W3C , NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] SLIDES ET DéMOS : AUTOUR DU W3C , NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Très bonne après-midi passée lors cette conférence avec le W3C, organisée par L' Inria sur les nouveaux standards, ce Mardi 14 Février, on sent vraiment que çà bosse au W3C, et l'avenir est très très prometteur pour le HTML5, notamment ...
Cliquez pour lire la suite de l'article par Gio GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|