0

I am working on images in current application and facing lot of issues like resize image , image quality etc.

I have seen lot of website uploading image with good quality and minimum size length. One thing that i noticed image quality does not loose when increase or decrease the dimensions.

So my question is What will be efficient techniques to handle following issues

  1. Reduce image size length
  2. Resize image dimensions

For example if i want minimum image dimensions should be (width = 800 * height=600) so how can i increase dimensions without respect to image quality and how decrease image dimensions according to ratio.

I am working on asp.net MVC3 C# but your suggestion in any language will be helpful for me.

Shoaib Ijaz
  • 5,347
  • 12
  • 56
  • 84
  • what ever size you change for the image, set its size mode property to normal or auto size. – Jibran Khan May 31 '13 at 10:43
  • You can take a look at [this](http://stackoverflow.com/questions/11959758/java-maintaining-aspect-ratio-of-jpanel-background-image/11959928#11959928) – MadProgrammer May 31 '13 at 11:11

1 Answers1

1

One thing that i noticed image quality does not loose when increase or decrease the dimensions.

If this is the case, then the image is a vector format, such as SVG - PNG and JPEG images will always lose their quality when you increase the size, since the pixels will be stretched. There's ways you can mitigate that, but no way to circumvent it completely.

If you want to scale an image in Java however with as good a quality as you can reasonably get:

BufferedImage scaled = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
AffineTransform at = new AffineTransform();
at.scale(2.0, 2.0);
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
BufferedImage scaledImage = scaleOp.filter(img, scaled);

The key part that determines how the image is scaled is AffineTransformOp.TYPE_BICUBIC, which generally gives the best results (as far as it can, anyway.) C# will no doubt have a similar switch that can be set. The scale factor is given by at.scale(2.0, 2.0);, which will increase length and height by two - if you want to, say, reduce the dimensions by half, use at.scale(0.5, 0.5).

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • @AskQuestion What do you mean by according to quality? Whenever you resize a non-SVG image, you're losing quality in some sense of the word. – Michael Berry May 31 '13 at 10:58
  • Ok quality mean resolution. i have uploaded two images on a website one image (980*327) have high quality and size 230KB after saving this image i checked image size is 136 KB and dimensions are ( 1873*625). 2nd image ( 600*400) was low quality so its dimensions remain same just reduce size.how can it will be done? – Shoaib Ijaz May 31 '13 at 11:11
  • @AskQuestion File size is not an indication of the image quality. Image size is determined by the format, the format options and the complexity of the image (how different the pixels are across the whole image) – MadProgrammer May 31 '13 at 11:13
  • @MadProgrammer i am just mentioned file size but my main point is image dimensions. what is strategy of image re-sizing for these two images? – Shoaib Ijaz May 31 '13 at 11:33
  • @* i am just mentioned -- > i have just mentioned – Shoaib Ijaz May 31 '13 at 12:05
  • @AskQuestion Check the link I left in the comments – MadProgrammer May 31 '13 at 12:31