468,119 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

Shrink .jpg to a new file

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
Jan 4 '06 #1
5 1655
Mark <ma**@nojunkmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 4 '06 #2
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.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Mark" <ma**@nojunkmail.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
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

Jan 4 '06 #3
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]
- mv*@spam.guard.caspershouse.com

"Mark" <ma**@nojunkmail.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
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

Jan 4 '06 #4
Sorry for not being precise. I'm interested in shrinking the size of the
image. Thanks again.

Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ed**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <ma**@nojunkmail.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
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


Jan 4 '06 #5
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]
- mv*@spam.guard.caspershouse.com

"Mark" <ma**@nojunkmail.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Sorry for not being precise. I'm interested in shrinking the size of the
image. Thanks again.

Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:ed**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <ma**@nojunkmail.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
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



Jan 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fibre Optic | last post: by
5 posts views Thread by BashiraInTrouble | last post: by
4 posts views Thread by Tommy.Vincent | last post: by
4 posts views Thread by Gary Bond | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.