Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

ImageHelper.cs

Description du code

ImageHelper.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Drawing;
  3. using System.IO;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using be.gaudry.observer;
  7.  
  8. namespace be.gaudry.model.drawing
  9. {
  10. public class ImageHelper
  11. {
  12.  
  13. public static bool isImg(string fileName)
  14. {
  15. fileName = fileName.ToUpper();
  16. return (
  17. fileName.EndsWith(".JPEG") ||
  18. fileName.EndsWith(".JPG") ||
  19. fileName.EndsWith(".GIF") ||
  20. fileName.EndsWith(".TIFF") ||
  21. fileName.EndsWith(".PNG") ||
  22. fileName.EndsWith(".BMP")
  23. );
  24. }
  25. /// <summary>
  26. /// Open a openfiledialog to select the image file
  27. /// to be diplayed in a PictureBox
  28. /// </summary>
  29. /// <param name="form">(Form</param>
  30. /// <param name="pictureBox"></param>
  31. public static void setImageLocation(Form form, PictureBox pictureBox)
  32. {
  33.  
  34. OpenFileDialog openImgDialog = new OpenFileDialog();
  35. openImgDialog.RestoreDirectory = true;
  36. openImgDialog.CheckFileExists = true;
  37. openImgDialog.Title = "Sélectionner une image...";
  38. openImgDialog.Filter = "Images|*.jpeg;*.jpg;*.gif;*.png;*.bmp;*.tiff|Joint Photographic Experts Group (.jpeg, .jpg)|*.jpeg;*.jpg|Graphical Interchange Format (.gif)|*.gif|Portable Network Graphic (.png)|*.png|Bitmap (.bmp)|*.bmp|Tagged Image File Format (.tiff)|*.tiff";
  39. openImgDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); //Config.DataDirPath;//Application.StartupPath;
  40. if (openImgDialog.ShowDialog(form) == DialogResult.OK)
  41. {
  42. pictureBox.ImageLocation = openImgDialog.FileName;
  43. }
  44. openImgDialog.Dispose();
  45. }
  46. /// <summary>
  47. /// Decorator of File.copy method
  48. /// </summary>
  49. /// <param name="oldPath">(String) Path of the old file</param>
  50. /// <param name="newPath">(String) Path of the new file</param>
  51. public static void copy(String oldPath, String newPath)
  52. {
  53. if (String.IsNullOrEmpty(oldPath))
  54. StaticObservable.notify(new Notification(Notification.VERBOSE.error, "Copie d'image", "Impossible de copier le fichier (le chemin du fichier source est vide)"));
  55. if (String.IsNullOrEmpty(newPath))
  56. StaticObservable.notify(new Notification(Notification.VERBOSE.error, "Copie d'image", "Impossible de copier le fichier (le chemin du fichier destination est vide)"));
  57. if (!oldPath.Equals(newPath))
  58. {
  59. try
  60. {
  61. if (oldPath.Contains("http"))
  62. {
  63. System.Net.WebClient webClient = new System.Net.WebClient();
  64. webClient.DownloadFile(oldPath, newPath);
  65. }
  66. else
  67. {
  68. File.Copy(oldPath, newPath, true);
  69. }
  70. }
  71. catch (UnauthorizedAccessException uae)
  72. {
  73. StaticObservable.notify(new Notification(Notification.VERBOSE.error, "Copie d'image", "Modification de l'image (Accès interdit)", uae));
  74. }
  75. catch (DirectoryNotFoundException dnfe)
  76. {
  77. StaticObservable.notify(new Notification(Notification.VERBOSE.error, "Copie d'image", "Modification de l'image (Chemin du répertoire non valide)", dnfe));
  78. }
  79. catch (NotSupportedException nse)
  80. {
  81. StaticObservable.notify(new Notification(Notification.VERBOSE.error, "Copie d'image", "Modification de l'image (Opération non supportée)", nse));
  82. }
  83. catch (Exception e)
  84. {
  85. StaticObservable.notify(new Notification(Notification.VERBOSE.error, "Copie d'image", "", e));
  86. }
  87. }
  88. }
  89.  
  90. public static String getImgInfos(String imgPath)
  91. {
  92. StringBuilder str = new StringBuilder("Infos sur le fichier :");
  93. if (File.Exists(imgPath))
  94. {
  95. FileInfo fi = new FileInfo(imgPath);
  96. str.AppendFormat("\n\nTaille \t\t: {0}\n", Units.getLengthString(fi.Length));
  97. str.AppendFormat("\nCréé le \t\t: {0}", fi.CreationTime.ToShortDateString());
  98. str.AppendFormat("\nModifié le\t\t: {0}", fi.LastWriteTime.ToShortDateString());
  99. str.AppendFormat("\nDernier accès le\t: {0}\n", fi.LastAccessTime.ToShortDateString());
  100. str.AppendFormat("\nNom \t\t: {0}", fi.Name);
  101. str.AppendFormat("\nType \t\t: {0}\n", fi.Extension);
  102.  
  103. Bitmap bmp = new Bitmap(imgPath);
  104. str.AppendFormat("\nHauteur \t\t: {0} pixels", bmp.Height);
  105. str.AppendFormat("\nLargeur \t\t: {0} pixels", bmp.Width);
  106. }
  107. return str.ToString();
  108. }
  109. /*
  110.   public static Image getThumbnail(String path, int width, int height)
  111.   {
  112.   Image bmp = Image.FromFile(path);
  113.   Double dif = Convert.ToDouble(Decimal.Divide(bmp.Width, bmp.Height));
  114.   width = Convert.ToInt32(Math.Ceiling(height * dif));
  115.  
  116.   Bitmap tn = new Bitmap(width, height);
  117.  
  118.   Graphics g = Graphics.FromImage(tn);
  119.  
  120.   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; //experiment with this...
  121.  
  122.   g.DrawImage(bmp, new Rectangle(0, 0, tn.Width, tn.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
  123.  
  124.   g.Dispose();
  125.   bmp.Dispose();
  126.  
  127.   return (Image)tn;
  128.   }
  129.  
  130.  
  131.  
  132.  
  133.   public static Image toThumbnailHighQuality(Image bmp, int width, int height)
  134.   {
  135.   Double dif = Convert.ToDouble(Decimal.Divide(bmp.Width, bmp.Height));
  136.   width = Convert.ToInt32(Math.Ceiling(height * dif));
  137.  
  138.   Bitmap tn = new Bitmap(width, height);
  139.  
  140.   Graphics g = Graphics.FromImage(tn);
  141.  
  142.   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
  143.  
  144.   g.DrawImage(bmp, new Rectangle(0, 0, tn.Width, tn.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
  145.  
  146.   g.Dispose();
  147.   bmp.Dispose();
  148.  
  149.   return (Image)tn;
  150.   }*/
  151.  
  152. public static Image getResized(Image image, int maxWidth, int maxHeight)
  153. {
  154. if (image.Width > maxWidth || image.Height > 16)
  155. {
  156. int newWidth = (image.Width > maxWidth) ? maxWidth : image.Width;
  157. int newHeight = image.Height * newWidth / image.Width;
  158. if (newHeight > maxHeight)
  159. {
  160. // Resize with height instead
  161. newWidth = image.Width * maxHeight / image.Height;
  162. newHeight = maxHeight;
  163. }
  164.  
  165. image = new Bitmap(image, new Size(newWidth, newHeight));
  166. }
  167. return image;
  168. }
  169. }
  170. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/drawing/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1714103448 26/04/2024 05:50:48
| _colors0 octets1541007202 31/10/2018 18:33:22
| _chart0 octets1541007202 31/10/2018 18:33:22
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/drawing/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csIconExtractor.cs5.18 Ko31/10/2018 18:33:08-refusé-
Afficher le fichier .cs|.csImageHelper.cs7.19 Ko31/10/2018 18:33:08-refusé-
Afficher le fichier .cs|.csBrolImage.cs6.29 Ko31/10/2018 18:33:08-refusé-
Afficher le fichier .cs|.csDibToImage.cs8.83 Ko31/10/2018 18:33:08-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-broldev-source-rf-model/drawing/ImageHelper.cs.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.