Shrink .jpg to a new file

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I'd like to automate the process of shrinking .jpg files using C#. I'd like
to point at 1000 files, shrink them to 30%, and then resave the new files.
I've seen the Graphics.DrawImage method, but this appears to be used for
display only?

What classes/method would be most useful?

Thanks in advance.

Mark
 
Mark said:
I'd like to automate the process of shrinking .jpg files using C#. I'd like
to point at 1000 files, shrink them to 30%, and then resave the new files.
I've seen the Graphics.DrawImage method, but this appears to be used for
display only?

What classes/method would be most useful?

Have you tried using Image.GetThumbnailImage? Alternatively, use
Graphics.DrawImage having created a new Graphics with
Graphics.FromImage. You'll need to create a new Bitmap to draw onto
first.
 
Hi,

the Bitmap class is the more appropiated, it has a method to get a thumbnail
from the image , you could use this.

In anycase I advise you to do a search for a third party tool also , you may
get a better performance.
 
Mark,

Are you talking about shrinking in terms of the size of the file, or the
size of the image, or are you looking to change the compression rate of the
JPEG? Which is it?
 
Sorry for not being precise. I'm interested in shrinking the size of the
image. Thanks again.

Mark

Nicholas Paldino said:
Mark,

Are you talking about shrinking in terms of the size of the file, or
the size of the image, or are you looking to change the compression rate
of the JPEG? Which is it?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark said:
I'd like to automate the process of shrinking .jpg files using C#. I'd
like to point at 1000 files, shrink them to 30%, and then resave the new
files. I've seen the Graphics.DrawImage method, but this appears to be
used for display only?

What classes/method would be most useful?

Thanks in advance.

Mark
 
Mark,

If you are interested in shrinking the size of the image by 30%, you
could use the GetThumbnailImage method on the Image class to resize the
image.

However, you have to be careful. If your image contains thumbnail data,
then it will use that and possibly scale it up (which results in a much
larger loss of quality usually than scaling down).

If there is no data in the thumbnail image, then the Image class will
just scale the image down, and that would work.

If there is thumbnail data, you will have to create a new Bitmap at the
appropriate size, and then draw the current image onto the new one (there
are methods on the DrawImage method on the Graphics class which will handle
the scaling for you).

It should also be noted that the quality of GDI+ (which the Graphics
instance is based on), is generally crap. You might not get the quality you
are looking for, and might have to look for a third party solution.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark said:
Sorry for not being precise. I'm interested in shrinking the size of the
image. Thanks again.

Mark

Nicholas Paldino said:
Mark,

Are you talking about shrinking in terms of the size of the file, or
the size of the image, or are you looking to change the compression rate
of the JPEG? Which is it?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark said:
I'd like to automate the process of shrinking .jpg files using C#. I'd
like to point at 1000 files, shrink them to 30%, and then resave the new
files. I've seen the Graphics.DrawImage method, but this appears to be
used for display only?

What classes/method would be most useful?

Thanks in advance.

Mark
 
Back
Top