Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

decrease image size C#

public static void SaveJpeg (string path, Image img, int quality) 
{ 
    if (quality<0  ||  quality>100) 
        throw new ArgumentOutOfRangeException("quality must be between 0 and 100."); 

     // Encoder parameter for image quality 
     EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality); 
     // JPEG image codec 
     ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg"); 
     EncoderParameters encoderParams = new EncoderParameters(1); 
     encoderParams.Param[0] = qualityParam; 
     img.Save(path, jpegCodec, encoderParams); 
} 

/// <summary> 
/// Returns the image codec with the given mime type 
/// </summary> 
private static ImageCodecInfo GetEncoderInfo(string mimeType) 
{ 
     // Get image codecs for all image formats 
     ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); 

     // Find the correct image codec 
     for(int i=0; i<codecs.Length; i++) 
         if(codecs[i].MimeType == mimeType) 
             return codecs[i]; 

     return null; 
 } 
Comment

PREVIOUS NEXT
Code Example
Csharp :: All Possible SubString 
Csharp :: type or namespace text could not be found unity 
Csharp :: Winform on exit run method 
Csharp :: C# fileinfo creation date 
Csharp :: how to iterate between hour range in c# 
Csharp :: dapper sql builder where 
Csharp :: meaning immutable and mutable 
Csharp :: how to use yield in c# 
Csharp :: dataannotations datetime range 
Csharp :: replace multiple characters in string c# 
Csharp :: linked list revrse 
Csharp :: defualtsize UWP c# 
Csharp :: c# combobox with text and value 
Csharp :: c# nullable generic 
Csharp :: instantiate prefab unity 
Csharp :: c# wpf row definition height * in code 
Csharp :: check if mouse is in frame unity 
Csharp :: unity 2d enemy patrol script 
Csharp :: c# how to append in array 
Csharp :: concat arrays .net 
Csharp :: unity unit tests 
Csharp :: Code to disable Debug.log 
Csharp :: hide numericUpDown arrows 
Csharp :: how to get the today date in c# 
Csharp :: c# .net automapper profile 
Csharp :: string trin c# 
Csharp :: c# window form align right bottom 
Csharp :: unity draw waypoints path 
Csharp :: top down view player movement 
Csharp :: number to character c# 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =