Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an old thread, but I have rewritten the Microsoft (as per Dustin Getz answer) to be a little more useful - shrinking GetEncoderInfo and making an extension on Image. Anyway nothing really new, but may be of use:</p> <pre><code> /// &lt;summary&gt; /// Retrieves the Encoder Information for a given MimeType /// &lt;/summary&gt; /// &lt;param name="mimeType"&gt;String: Mimetype&lt;/param&gt; /// &lt;returns&gt;ImageCodecInfo: Mime info or null if not found&lt;/returns&gt; private static ImageCodecInfo GetEncoderInfo(String mimeType) { var encoders = ImageCodecInfo.GetImageEncoders(); return encoders.FirstOrDefault( t =&gt; t.MimeType == mimeType ); } /// &lt;summary&gt; /// Save an Image as a JPeg with a given compression /// Note: Filename suffix will not affect mime type which will be Jpeg. /// &lt;/summary&gt; /// &lt;param name="image"&gt;Image: Image to save&lt;/param&gt; /// &lt;param name="fileName"&gt;String: File name to save the image as. Note: suffix will not affect mime type which will be Jpeg.&lt;/param&gt; /// &lt;param name="compression"&gt;Long: Value between 0 and 100.&lt;/param&gt; private static void SaveJpegWithCompressionSetting(Image image, string fileName, long compression) { var eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(Encoder.Quality, compression); var ici = GetEncoderInfo("image/jpeg"); image.Save(fileName, ici, eps); } /// &lt;summary&gt; /// Save an Image as a JPeg with a given compression /// Note: Filename suffix will not affect mime type which will be Jpeg. /// &lt;/summary&gt; /// &lt;param name="image"&gt;Image: This image&lt;/param&gt; /// &lt;param name="fileName"&gt;String: File name to save the image as. Note: suffix will not affect mime type which will be Jpeg.&lt;/param&gt; /// &lt;param name="compression"&gt;Long: Value between 0 and 100.&lt;/param&gt; public static void SaveJpegWithCompression(this Image image, string fileName, long compression) { SaveJpegWithCompressionSetting( image, fileName, compression ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload