LoginSignup
0
2

More than 3 years have passed since last update.

低品質Jpegを作るプログラム

Last updated at Posted at 2019-12-12

DPZ
写真を限界までJPEG圧縮すると見えてくる世界

に触発されて、低品質Jpegを作るプログラム

JpgQlyZero.cs
//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe JpgQlyZero.cs

using System.Drawing;
using System.Drawing.Imaging;

public class JpgQlyZero
{
 public static void Main(string[] args)
 {
    if(args.Length==2){

        string path1; //in file name
        string path2; //out file name
        path1 = @".\" + args[0];
        path2 = @".\" + args[1];

        Bitmap image1;
        image1 = new Bitmap(path1, true);

        // Jpenの保存品質。小さいほど悪い
        int quality = 0; 
        ImageCodecInfo je = null;

        foreach (ImageCodecInfo ici in ImageCodecInfo.GetImageEncoders()) {
            if (ici.FormatID == ImageFormat.Jpeg.Guid) {
            je = ici;
            break;
            }
        }
        EncoderParameter ep= new EncoderParameter(Encoder.Quality, quality);
        EncoderParameters eps = new EncoderParameters(1);
        eps.Param[0] = ep;

        image1.Save(path2, je, eps);
    }
 }
}

(※画像は、Windows10のデスクトップ壁紙画像から)

劣化後
bb.jpg

劣化前
A1.JPG

※以下のソースを参考、利用してます

品質を指定してJPEG画像を保存するには?

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2