Avatar of jdhackett
jdhackett
Flag for Ireland asked on

Change file size of image

Hi
I wish to shrink the file size of jpg images, using VB.Net 2015.
So the user would select an image, then a smaller image would be saved. These images are usually photographs of 2Mb, can be up to 8Mb.
The smaller photograph:
           
  • should be 200k or less.
  •             The width/height ratio remain the same.
  •             Save to the same folder, but with a new name

I've seen some code which resizes by a percentage. However I want to make sure the size is always under 200k, no matter the size of the original.
What would be the best way to do this in VB.Net?
Thanks
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
funwithdotnet

8/22/2022 - Mon
AndyAinscow

>>I've seen some code which resizes by a percentage.
Use that code and keep reducing the percentage until the file size is what you desire.

Logic.
percentreduction = 90   90 % of original is target
while filesize > 200000
  percentreduction = percentreduction - 10
  reducefile percentreduction
end while
jdhackett

ASKER
Not a bad idea Andy, but won't it be slow to save the file multiple times and then get the file size?
I was hoping there was a setting within the vb.net image control that lets you specify the file size.
ASKER CERTIFIED SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
funwithdotnet

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes