-1

I want to resize all my images to 50 kb. It doesn't matter what the height and width will be.

I know how to resize using a static height and width:

public static Image resizeImage(Image imgToResize, Size size)
{
    return (Image)(new Bitmap(imgToResize, size));
}
yourImage = resizeImage(yourImage, new Size(50,50));

How do i resize an image without specifying a static height and width? but by specifying a new size in kb

scatman
  • 14,109
  • 22
  • 70
  • 93
  • I suppose you want to maintain also the aspect/ratio of the image? – Steve Feb 05 '18 at 09:32
  • Is it an option to crop each image to 1x1 pixels and pad it with metadata till it's 50 KB? Please read [ask] and show some sensible requirements and also what you have tried. Due to the varying nature of image data I'd say it's pretty hard to determine the available resolution for a given desired file size. – CodeCaster Feb 05 '18 at 09:35

1 Answers1

0

I'd say you have no possibility to know the file size until you have the file. So in my opinion if you want to achieve this, you just have to resize, check the file size (writing to MemoryStream is probably already a good aproximation) and than resize again if not satisfied with the result. No method that does it automatically that I'm aware of..

Maxim Zabolotskikh
  • 3,091
  • 20
  • 21