Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello,
I have a doubt regarding image processing in .NET. Probably a little weird. I have images taken from my camera from time to time which are given ridiculous sizes of 5MB or more. I find that opening them in Paint and then saving them to a JPEG (once again) reduces the size to a manageable one. This is a little tedious when I have to do this for probably a lot of images (hundreds) so I want to write an app to do this.

I would like any reference links you can provide which can guide me to understand the logic of creating this app. Is it possible to write this app which sort of uses Paint to save an existing JPEG file to a new JPEG file?

I hope I made sense there. Thanks!
Posted
Updated 22-Feb-12 19:23pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Feb-12 1:20am    
Tag it: WPF, Forms (System.Drawing), Silverlight, ASP.NET, what?
--SA
Nithin Sundar 23-Feb-12 1:23am    
Oh there it is. Thanks. Tagged it now. I'm probably okay with WPF or Forms.
Sergey Alexandrovich Kryukov 23-Feb-12 1:36am    
Oh, thank you and sorry for misleading your a bit. Basically, main alternatives are System.Drawing vs. WPF. If you use Forms, it's reduced to using System.Drawing. Anyway, I provided a complete answer, please see.
--SA
Nithin Sundar 23-Feb-12 1:43am    
No problem at all. You were only making the question look better. Thanks!
krumia 23-Feb-12 5:44am    
Off the topic: JPEG images get distorted every time they are modified and saved. Just open and save a JPEG using paint about 5 times and you will notice a considerable reduction of image quality, especially in those one-color areas. Hope you're aware of this.

1 solution

There are enough of ready-to-use utilities and libraries, such as Open Source and multi-platform ImageMagic. Please see:
http://en.wikipedia.org/wiki/ImageMagick[^],
http://www.imagemagick.org/[^].

As it comes with command-line utilities, you can easy write a batch file of one or two lines, ordering something like: "convert all files in working directory", or the same in specified directory, or the same in working directory and all sub-directories, recursively, of "from the specified file list", or anything like that.

The required ability to write batch files is rudimentary for an advanced user, not even a software developer, you can read about it in any elementary manual.

Writing your own C# code is also pretty easy:
http://stackoverflow.com/questions/41665/bmp-to-jpg-png-in-c-sharp[^].

—SA
 
Share this answer
 
Comments
Varun Sareen 23-Feb-12 1:35am    
my 5: good links
Sergey Alexandrovich Kryukov 23-Feb-12 1:37am    
Thank you, Varun. It just works... :-)
--SA
Nithin Sundar 23-Feb-12 1:36am    
Thanks for those. Will look into them. Is the utility more close to what paint is doing or will the C# code do it better? I think that the C# code would be more suitable since paint is also built on the same type of stuff?
Sergey Alexandrovich Kryukov 23-Feb-12 1:43am    
"Paint" or not is irrelevant. Bitmap is bitmap. Who needs paint, anyway? Trash it!

You need just too things: Open Source GIMP and IrfanView. First is a very good editor, second one -- a very quick viewer and converter. Both a must-have.
For vector graphics you better use Open Source InkScape. All three tools are free of charge and better them most proprietary.

Quality of conversion to the lossy format depends! Usually, the best quality and options are offered by IrfanView, usually (it's not just conversion -- millions of operations). With ImageMagic and batch mode -- learn all the options (there are many!) and experiment.

Anyway, will you consider accepting the answer formally (green button)?
--SA
Nithin Sundar 23-Feb-12 1:46am    
I've already accepted it. It was good and was screaming "Accept or....". ^_^
I'll have to try using GIMP and Irfanview. I was talking about paint in a more "Opens and saves to a smaller size" thingy. Forgive this newbie for not stepping outside the Paint world.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900