C# code

Asked By jack
31-Jul-10 03:50 PM
Earn up to 0 extra points for answering this tough question.
i need to know how we could enlarge and reduce an image by using c#. thanks alot.

  re: C# code

Super Man replied to jack
31-Jul-10 11:27 PM

you can make use of the following javascript function in your code :

function Imgwtest()

{

document.getElementById("imgld").style.width='500px';

document.getElementById("imgld").style.height='500px';

}

function Imgwtest1()

{

document.getElementById("imgld").style.width='800px';

document.getElementById("imgld").style.height='500px';

}



< img src ="Images/Ascent.jpg" id='imgld' onmousemove ="Imgwtest();" onmouseout ="Imgwtest1();"/ >

  re: C# code

Abhinav Singh replied to jack
03-Aug-10 08:14 AM
I think you want to resize the image using C# so here is the code:

public void ResizeFromStream(string ImageSavePath, int MaxSideSize, Stream Buffer)
     {
       int intNewWidth;
       int intNewHeight;
       Image imgInput = Image.FromStream(Buffer);
 
       //Determine image format
       ImageFormat fmtImageFormat = imgInput.RawFormat;
 
       //get image original width and height
       int intOldWidth = imgInput.Width;
       int intOldHeight = imgInput.Height;
 
       //determine if landscape or portrait
       int intMaxSide;
 
       if (intOldWidth >= intOldHeight)
       {
         intMaxSide = intOldWidth;
       }
       else
       {
         intMaxSide = intOldHeight;
       }
 
 
       if (intMaxSide > MaxSideSize)
       {
         //set new width and height 
         double dblCoef = MaxSideSize / (double)intMaxSide;
         i ntNewWidth = Convert.ToInt32(dblCoef * intOldWidth);
         intNewHeight = Convert.ToInt32(dblCoef * intOldHeight);
       }
       else
       {
         intNewWidth = intOldWidth;
         intNewHeight = intOldHeight;
       }
       //create new bitmap
       Bitmap bmpResized = new Bitmap(imgInput, intNewWidth, intNewHeight);
 
       //save bitmap to disk
       bmpResized.Save(ImageSavePath, fmtImageFormat);
 
       //release used resources
       imgInput.Dispose();
       bmpResized.Dispose();
       Buffer.Close();
     }

By using this method you can resize the image as per your need.
Create New Account