Hi,
Karen Hill wrote:
> How do I get the file size of a JPEG and resize it if it is too big in
> terms of MB or KB? I am using Windows Forms, .NET 2.0, C#. I want to
> put this image in a database so I want to make sure it isn't too large
> (ideally no more than 200K. I tried discovering the size of a JPEG
> using sizeof but that only works with built in types like int and long.
>
>
> regards,
>
> karen
The other replies show you how to get the file's size. To resize it, you
can use this (this example divides an image's size by 2 and saves it to
a given stream):
Bitmap originalImage = new Bitmap( path );
Bitmap newImage = new Bitmap( originalImage,
originalImage.Width / 2,
originalImage.Height / 2 );
newImage.Save( outputStream, originalImage.RawFormat );
originalImage.Dispose();
originalImage = null;
Note however that the built-in resizing algorithms are not very good,
and the resulting image might not look as nice as if you resized it
using a better algorithm, or an external program.
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering:
http://www.galasoft-LB.ch
PhotoAlbum:
http://www.galasoft-LB.ch/pictures
Support children in Calcutta:
http://www.calcutta-espoir.ch