Resize image in asp.net

T

Tomo

I have some code for resizing image (create thumbnail) but there is no
compression. Thumbnail image is smaller in pixels, but in kilobytes is
bigger. How can I create smaller file? I need code in VB or C#.

// Get the path of the original Image

string displayedImg = Server.MapPath("~") + "/Testing.jpg";

// Get the path of the Thumb folder

string displayedImgThumb = Server.MapPath("~") + "/Images/";

// Get the original image file name

string imgFileName = System.IO.Path.GetFileName(displayedImg);

// Load original image

System.Drawing.Image myimg = System.Drawing.Image.FromFile(displayedImg);

// Get the thumbnail 100 X 100 px

myimg = myimg.GetThumbnailImage(1280, 825, null, IntPtr.Zero);

// Save the new thumbnail image

myimg.Save(displayedImgThumb + imgFileName, myimg.RawFormat);
 
A

Alberto Poblacion

Tomo said:
I have some code for resizing image (create thumbnail) but there is no
compression. Thumbnail image is smaller in pixels, but in kilobytes is
bigger. How can I create smaller file? I need code in VB or C#.
[...]
myimg.Save(displayedImgThumb + imgFileName, myimg.RawFormat);

Instead of saving the Image in RawFormat (which has no compression),
save it using one of the compressing ImageFormats. For instance:

myimg.Save(displayedImgThumb +
Path.GetFileNameWithoutExtension(imgFileName)+".jpg", ImageFormat.Jpeg);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top