C# .NET - C# code

Asked By jack
31-Jul-10 03:50 PM
i need to know how we could enlarge and reduce an image by using c#. thanks alot.
  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();"/ >

  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
help
v6001-x64.msu' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ ImpexSetUp \ ImpexSetUp \ ImpexSetUp.vdproj ImpexSetUp KRISHNADAS dotNetFX20 \ aspnet.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 2 dotNetFX20 \ aspnet_64.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 3 dotNetFX20 \ clr.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 4 dotNetFX20 \ clr_64.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 5 dotNetFX20 \ crt.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 6 dotNetFX20 \ crt_64.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 7 dotNetFX20 \ dw.msp' in item '.NET Framework 3.5 SP1' can not be located on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 8
GZipStream Class GZipStream is a class that allows the compression of data through to another stream using the GZIP compression method. GZipStream Properties Name Description BaseStream Gets the underlying stream. CanRead Determines whether the stream supports reading while decompressing a file. (Inherited from the Stream class .) CanSeek Determines whether the stream supports seeking. (Inherited from the Stream class .) CanTimeout Determines whether the stream can time out . (Inherited from the Stream class .) CanWrite Determines whether the stream can be written to. (Inherited from the Stream class
HttpWebResponse classes to request and retrieve the requested file. The data are read into a buffer. A FileStream class is used to save the file to disk. In this example, a doppler radar map that covers the area I live is requested to a file called "weather.jpg". Since the data are downloaded and read into the buffer asynchronously, a loop is required to read and keep track of how many bytes have been read, and the point in the stream where the next read should start. The loop will continue until the buffer is full or 0 bytes are read, indicating the end of the stream has been reached. The buffer must be sized large enough to hold the file. This is not a problem in WebRequestFactory.Create (http: / / maps.weather.com / web / radar / us_orl_ultraradar_large_usen.jpg); HttpWebResponse ws = (HttpWebResponse)wr.GetResponse(); Stream str = ws.GetResponseStream(); byte [] inBuf = new byte [100000]; int bytesToRead = ( int ) inBuf.Length; int bytesRead
the thumbnail in PNG format. / / You may change it to a diff format with the ImageFormat property thumbNailImg.Save ( Request.PhysicalApplicationPath + " pics \ " + MyString , ImageFormat.Png); thumbNailImg.Dispose(); / / Display the original & the newly generated thumbnail Image1.AlternateText = " Original image " ; Image1 must be less than " & upload_max_size & "Kb" 28: else 29: try 30: originalImg = System . Drawing . Image . FromStream ( fileFld . InputStream ) 31: ' work out the width / height for the thumbnail. Preserve aspect ratio and cellpadding = "2" cellspacing = "2"> <tr> <td bgcolor = "#CCDDEE" align = "center"> Uploaded Images To Server Hard Disk < / td> < / tr> <tr> <td bgcolor = "#F7F7F7" align = "center"> i. Image Files < / td> < / tr> <tr> <td Imaging; namespace Sample.Content.Items { public class C_Image { public void ResizeFromStream(string ImageSavePath, int MaxSideSize, Stream Buffer) { / / . . . } / / . . . } } / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Your *.aspx or file: / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / using System; using System.Web; using System.Web.UI.WebControls; using