Reputation: 1052
I just wrote a simple image resizer in Python 2.7 using the PIL environment. Because I wanted a nice and fast GUI, I decided to port it to C#. My Python code looks like this
k = I.open(f)
h = int(k.size[1] / float(k.size[0]) * maxWidth)
s = (maxWidth, h) if maxWidth < k.size[0] else k.size #only care about landscape
k = k.resize(s, I.ANTIALIAS)
k.save(os.path.join(outdir, i))
whilst my C# port looks like this
Bitmap bitmap = new Bitmap(image, w, h); //image = Image.FromFile()
bitmap.Save(destPath); //disposing later in the code
I'm running into some strange file size problems. With Python I'm resizing the image to about 1500x1000 pixels and the file is about 180kB big. The file created by my C# application at 1500x1000 pixels is about 2000kB big, so I guess there's some unneccessary information added by C#.
How can I reduce my image's file size in C# like I can in Python?
Upvotes: 0
Views: 180
Reputation: 26446
Depending on the type of image, you can set additional properties. Jpeg for instance has a "quality" setting, you can specify while saving the image. See for example msdn.microsoft.com/en-us/library/bb882583(v=vs.110).aspx
Note that these EncoderParameters
differ per file format. See http://msdn.microsoft.com/en-us/library/bb882589(v=vs.110).aspx to determine which parameters are supported per format.
Upvotes: 2
Reputation: 2032
You could try saving it in a different format.
bitmap.Save("C:\temp",ImageFormat.Jpeg);
Upvotes: 0