I recently had to write an application to convert JPEG from low compression to high compression because of the huge size of high resolution pictures. Here is some sample code from the Application JCompressor:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
public static void SaveJpeg(string path, Image img, int quality, string fn1)
{
if (quality < 0 || quality > 100)
throw new ArgumentOutOfRangeException
("quality must be between 0 and 100.");
// Encoder parameter for image quality EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
// Jpeg image codec
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save(path + @"\Converted" + "-" + DateTime.Now.Second.ToString()+ "_" + fn1, jpegCodec, encoderParams);
}
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;
}
usage: SaveJpeg(path1, image1, 40, filename);
Various Scripts and Application Code Segments for .NET, VB, C#, C++, C, Java, JavaScript, HTML, Python, Perl, AutoIT, Batch, ASP Classic, Objective-C, Swift, Unreal Engine 4, Unity3D & others. Also contains numerous IT tidbits, procedures, and tricks including Technology Hacks on various platforms.
Showing posts with label Graphics JPEG JPG Conversion C# Sharp. Show all posts
Showing posts with label Graphics JPEG JPG Conversion C# Sharp. Show all posts
Wednesday, May 19, 2010
Subscribe to:
Posts (Atom)
Generating "Always On Top" NSWindow in macOS across all detected displays
Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift Langues, you m...
-
This simple script is how to submit scores and points to the Game Center from a Unity3D Game. People use the prime31 plugin, and pay the e...
-
Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift Langues, you m...
-
Recently Possess () has been deprecated from UE4 , and when writing classes based on AAIController you have to use the function OnPossess ...
