reducing image file size
-
hey i have a site and i bulid administrator section where he can upload Images to the site. the images sould be on Size 532x301 so im resizing them with this method
Bitmap b; Image i; Graphics g; b = new Bitmap(width, height); i = Image.FromHbitmap(b.GetHbitmap()); g = Graphics.FromImage(i); g.DrawImage(img, 0f, 0f, width, height); g.Dispose(); img.Dispose(); return i;
after the resize the image file size is 0.5 MB (it was 5mb before)... i want to reduct the image file size to (100k -200k) so the site could be faster, also i dont have alot of space on my host... can anyone help me ?
-
hey i have a site and i bulid administrator section where he can upload Images to the site. the images sould be on Size 532x301 so im resizing them with this method
Bitmap b; Image i; Graphics g; b = new Bitmap(width, height); i = Image.FromHbitmap(b.GetHbitmap()); g = Graphics.FromImage(i); g.DrawImage(img, 0f, 0f, width, height); g.Dispose(); img.Dispose(); return i;
after the resize the image file size is 0.5 MB (it was 5mb before)... i want to reduct the image file size to (100k -200k) so the site could be faster, also i dont have alot of space on my host... can anyone help me ?
michael@cohen wrote:
b = new Bitmap(width, height); i = Image.FromHbitmap(b.GetHbitmap()); g = Graphics.FromImage(i);
How utterly bizarre. This is a waste of time. You can call Graphics.FromImage on a Bitmap, in fact, because of bugs in .NET, even if you create an Image, a Bitmap is created. You should use using blocks to auto dispose where you can. If you want images to be smaller, try saving them as jpeg or another compressed format. Otherwise, they are the size of the number of pixels x 3, you can't change that.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
hey i have a site and i bulid administrator section where he can upload Images to the site. the images sould be on Size 532x301 so im resizing them with this method
Bitmap b; Image i; Graphics g; b = new Bitmap(width, height); i = Image.FromHbitmap(b.GetHbitmap()); g = Graphics.FromImage(i); g.DrawImage(img, 0f, 0f, width, height); g.Dispose(); img.Dispose(); return i;
after the resize the image file size is 0.5 MB (it was 5mb before)... i want to reduct the image file size to (100k -200k) so the site could be faster, also i dont have alot of space on my host... can anyone help me ?
Hi, your code could be simplified to a single constructor, see
new Bitmap(Image, Size)
, however that would lead to the same result. As Christian said, the smallest file will be obtained by saving it in a format that applies compression, so use JPEG for it. :)Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!