Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reduce image size

9 views
Skip to first unread message

Eduard Faschang

unread,
May 14, 2004, 1:01:26 PM5/14/04
to
Hallo

I have picture with a bis size as 1 MB (digital photos).
I am looking for an example to reduce the file size with c#.
After reducing I want store the smalll file in a database.

Mybe anybody has a exaplme or idea.

Thank a lot

Edi


Justin Rogers

unread,
May 14, 2004, 1:14:07 PM5/14/04
to
Do you want to lower quality or change the size. I have a 5 megapixel camera,
and I use the following
code to reduce the pixel count to an 800x600 shot. If you are doing a bunch of
these then you'll also
want to take a look at my ImageFast library which cuts down the load time for
images from file by about
10-100 times depending on the image.

http://weblogs.asp.net/justin_rogers/articles/131704.aspx

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

public class LowerQuality {
private static void Main(string[] args) {
if ( args.Length < 2 ) {
return;
}

DirectoryInfo source = new DirectoryInfo(args[0]);
DirectoryInfo target = new DirectoryInfo(args[1]);

if ( source.Exists && target.Exists ) {
FileInfo[] files = source.GetFiles("*.jpg");
foreach(FileInfo fi in files) {
Bitmap sourceImage = new Bitmap(fi.FullName);
Bitmap targetImage = new Bitmap(800, 600);

using(Graphics gfx = Graphics.FromImage(targetImage)) {
gfx.DrawImage(
sourceImage,
new Rectangle(0, 0, targetImage.Width,
targetImage.Height),
new Rectangle(0, 0, sourceImage.Width,
sourceImage.Height),
GraphicsUnit.Pixel);
gfx.Dispose();
}
targetImage.Save(Path.Combine(target.FullName, fi.Name),
ImageFormat.Jpeg);
}
}
}
}


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Eduard Faschang" <m...@tznetz.com> wrote in message
news:O2jifUdO...@TK2MSFTNGP10.phx.gbl...

Eduard Faschang

unread,
May 14, 2004, 5:11:57 PM5/14/04
to
Thank you

I will dry it - Edi

"Justin Rogers" <Jus...@games4dotnet.com> wrote in message
news:eRAugbdO...@TK2MSFTNGP09.phx.gbl...

Steve McLellan

unread,
May 18, 2004, 5:38:23 AM5/18/04
to
Also check out GetThumbnail (in Image) - it doesn pretty much the same thing
as your resize code.

Steve

"Justin Rogers" <Jus...@games4dotnet.com> wrote in message
news:eRAugbdO...@TK2MSFTNGP09.phx.gbl...

0 new messages