Resized image

Hello,

I have very basic knowledge of ASP.net. I am using following script to resize and image, but the problem is it increases the disk volume of resized image to almost 4 times or original image.

Example:
Original Image: 1024 x 769px and Disk space: 135 KB
Resized Image: 600 x 380px and Disk space: 825KB

Notice resized image becomes 825KB.

dim g1 as System.Drawing.Image = System.Drawing.Image.FromFile(txtGetImage)
dim thisFormat1=g1.rawformat

 '#600
 height = g1.Height / (g1.Width / 600)
		 
 dim imgOutput1 as New Bitmap(g1, 600, height)  
 imgOutput1.Save(txtMedium)
     g1.dispose()
 imgOutput1.dispose() 

Any idea, any help will be greatly appriciated.

Thanks!

I have very basic knowledge of ASP.net so did not quite understand what you referred. I just need to resize images with minimum loss of quality and resized image can be in any format (gif, jpeg, jpg, png etc etc)

Right, so you are loading the compressed file and saving a bitmap with no compression. So of course the file is larger. Now, even with compression, you might not do that great – the JPEG compression that image manipulation programs can make is worlds ahead of what the BCL makes.

The file format can be in JPG, JPEG or GIF.

That’s the only way I know of that would keep the file weight the same while having the rendered file dimensions different.

Not that I’d recommend doing it, but I’ve seen it done often enough. It seems there are plenty that either don’t know how or can’t be bothered to use an application to optimize their image files.

Yes, Don’t resize the file. Specify the dimensions you want in the mark-up and it will render at those dimensions while retaining the original file weight.

I have very basic knowledge about ASP.net. Is there anyway to keep the resized image bytes same as original file?

^^^^Why? You’ll end up with oversized file downloads and lots of artifacts in the images.

I was going to mention System.Drawing.Graphics but webcosmo already did in his link. Using it you can use InterpolationMode and SmoothingMode to allow for a higher quality result.

jpeg, jpj,… are already compressed files, so if you take a compressed file and then render it as a bitmap file (which is not compressed), the size will be different. So you have to take that into consideration when dealing with images

Use this
<img ID=XYZ src=“your path image” />

Set ID height and Width inside asp.net coding, your image automatically resize.

That neither changes the file size nor the actual dimensions of the image.

thats not supposed to happen if done right.
long time ago i wrote an article on resizing image, its not perfect but you would get some idea

cosmocentral.com/2007/10/create-high-quality-thumbnail-resize-image-dynamically-asp-net-c-code/

What file format was the original? Bitmaps will generally be larger than any modern compressed format . . .