LoginSignup
0
1

More than 5 years have passed since last update.

画像平均化

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

using System.Drawing;

public class syuku02
{
 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];

        //int rt =3;

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

        Bitmap canvas = new Bitmap((int)image1.Width, (int)image1.Height);
        Graphics g = Graphics.FromImage(canvas);
        Color pClr;
        SolidBrush b;
        int x;
        int y;
        int xi;
        int yi;
        int r1;
        int g1;
        int b1;

        for(x=1;x<(int)image1.Width-6;x+=6){
            for(y=1;y<(int)image1.Height-6;y+=6){
                r1=0;g1=0;b1=0;
                for(xi=0;xi<6;xi+=1){
                    for(yi=0;yi<6;yi+=1){
                        pClr = image1.GetPixel(x + xi, y + yi);
                        r1 += (int)pClr.R;
                        g1 += (int)pClr.G;
                        b1 += (int)pClr.B;
                    }
                }
                //pClr = Color.FromArgb(255,255,255);
                //b = new SolidBrush(pClr);
                //g.FillRectangle(b, x, y, 6, 6);

                int t=8;
                r1 = ((int)(r1/(360*t)))*10*t;
                g1 = ((int)(g1/(360*t)))*10*t;
                b1 = ((int)(b1/(360*t)))*10*t;
                pClr = Color.FromArgb(r1,g1,b1);
                b = new SolidBrush(pClr);
                g.FillRectangle(b, x, y, 6, 6);
                //g.FillRectangle(b, x+1, y+1, 5, 5);
                }
        }

        canvas.Save(path2, System.Drawing.Imaging.ImageFormat.Png);
    }
 }

}
0
1
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
1