Click here to Skip to main content
16,006,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Just read some articless on resize image but can not find one that can do reduce the size after the user upload a image from digital phone camera?

What I am looking for is a facility to do the resize on the fly - immediately after user upload to the web server? Can anyone point a direction?

rgds,
kfl.
Posted

1 solution

Hi KF!

I just scratched this from http://www.switchedonthecode.com:

C#
private static Image resizeImage(Image imgToResize, Size size)
{
   int sourceWidth = imgToResize.Width;
   int sourceHeight = imgToResize.Height;

   float nPercent = 0;
   float nPercentW = 0;
   float nPercentH = 0;

   nPercentW = ((float)size.Width / (float)sourceWidth);
   nPercentH = ((float)size.Height / (float)sourceHeight);

   if (nPercentH < nPercentW)
      nPercent = nPercentH;
   else
      nPercent = nPercentW;

   int destWidth = (int)(sourceWidth * nPercent);
   int destHeight = (int)(sourceHeight * nPercent);

   Bitmap b = new Bitmap(destWidth, destHeight);
   Graphics g = Graphics.FromImage((Image)b);
   g.InterpolationMode = InterpolationMode.HighQualityBicubic;

   g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
   g.Dispose();

   return (Image)b;
}


I sure do hope you meant ASP.net and not ASP. ASP is dead and should have been buried a long time ago :) .
Nevertheless, I hope the code snippet helps you!


Cheers,


Manfred
 
Share this answer
 
Comments
KFLee 6-Dec-10 21:47pm    
Hi, thanks, I shall test i. Backward compatibility is always a problem for many to keep the head above the water. We do use both ASP and ASP.net. But a matter of interest, why you think ASP should be dead and buried? It has a lousy strcuture I would agree but it works anyway! Your comment remind me those days when we would agrue strongly against Basic (now VB) as a language for the low intelligent? In 1980s, C/Pascal/Algol are the 'good' computer languages! Just wonder what is the best web language now a day?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900