Follow by Email

Wednesday, 11 February 2015

Convert httppostedfilebase to image in C# and image re-sizing in c#

 private string UploadFile(HttpPostedFileBase postedFile)
        {
            if (postedFile.ContentLength > 0)
            {
                var filename = Path.GetFileName(postedFile.FileName);

                System.Drawing.Image sourceimage =
                    System.Drawing.Image.FromStream(postedFile.InputStream);

                Bitmap newImage = new Bitmap(5, 5);
                using (Graphics gr = Graphics.FromImage(newImage))
                {
                    gr.SmoothingMode = SmoothingMode.HighQuality;
                    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    gr.DrawImage(sourceimage, new Rectangle(0, 0, 5, 5));
                }
            }

}

0 comments:

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha