.Net & SharePoint '07

Technical blog for .Net and all SharePoint 2007 related Information

About the author

Me(Prince) and my wife are B.E in I.T & C.S.E respectively.  I a certified MCPD: Web from 2007 Dec. I am Intrestes in Web Application, MOSS, EPM, etc.
Now working with Deira International School, as IT Application & Help Manager. I have started my career as "Software Developer" @  REACH Sewn Technologies and Consulting Pvt. Ltd, Bangalore India from Oct 2004 to Feb 2006, then as "Web & Intranet Developer" @ Fosroc International Ltd, Dubai from April 2006 to Sep 2009.
You can catch me on mail@jpy-tech.com or mail@princepy.com. Or on 00971 - 50 - 4284530 

Google Translate

Tag cloud

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

RecentComments

Comment RSS

Google Your Location


ASP.NET Image / Photo Cropper / Resize in C#

thanks to ASP.NET Image / Photo Cropper in C#

You can skip to the demo by clicking here
You can download the source code by clicking here

Sanjay Uttam used javascript obtained from http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/

Source : PhotoCropperASP.NetC#.zip (501.17 kb)

XPS Doc: ASP.NET C# - Image Or Photo Cropping.xps (547.48 kb)

protected byte[] CropImageFile(byte[] imageFile, int targetW, int targetH, int targetX, int targetY)
    {
        MemoryStream imgMemoryStream = new MemoryStream();
        System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(new MemoryStream(imageFile));

        Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);
        bmPhoto.SetResolution(72, 72);
  
        Graphics grPhoto = Graphics.FromImage(bmPhoto);
        //Adjust settings to make this as high-quality as possible 
        grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

        try
        {
            grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH),
                                targetX, targetY, targetW, targetH, GraphicsUnit.Pixel);
            //Only JPG format for this demo
            bmPhoto.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
        catch (Exception e)
         ... //removed code to stay concise
        return imgMemoryStream.GetBuffer();
    }

Tags: , ,
Posted by Admin on Monday, January 18, 2010 10:25 PM
Permalink | Comments (0) | Post RSSRSS comment feed