3

i want to crop a photo retrieved from database, i have done the following to retrieve the image from the database

protected void Page_Load(object sender, EventArgs e) { MemoryStream stream = new MemoryStream(); SqlConnection connection = new SqlConnection(@"Data Source=localhost;Initial Catalog=card;User Id=sa;Password=db2admin;"); try { connection.Open(); SqlCommand command = new SqlCommand("select Photo from iffcar", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Jpeg); } catch (Exception ee) { connection.Close(); stream.Close(); HttpContext.Current.Response.Write(ee.Message); } } 

The image that is retrieved is displayed inside the browser.

Now i am stuck at how to crop this image,i want to allow the user to crop the image retrieved from the database and store the cropped image to be passed onto crystal report.

Is this possible? If so than is there any tutorial or help which would guide me to my end requirement.please help me to understand how to proceed with my query

1
  • maybe you should have a look at this project:code.google.com/p/jcrop Commented May 11, 2011 at 9:33

3 Answers 3

1

Take a look at GDI+ libraries and also the System.Drawing namespace. You can also use Windows Imaging Components.

Here's a basic walk-through.

Sign up to request clarification or add additional context in comments.

Comments

0

Fill in the ??s and try this:

 connection.Open(); SqlCommand command = new SqlCommand("select Photo from iffcar", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); int croppedWidth = ??, croppedHeight = ??, cropOffsetX = ??, cropOffsetY = ??; var croppedBitmap = new Bitmap(croppedWidth, croppedHeight); var graphics = Graphics.FromImage(croppedBitmap); graphics.DrawImage(bitmap, -cropOffsetX, -cropOffsetY, bitmap.Width, bitmap .Height); Response.ContentType = "image/gif"; croppedBitmap.Save(Response.OutputStream, ImageFormat.Jpeg); 

3 Comments

if it dont Crop the image then i mis understood the question, i thought that it will,but how ever your MINUS 1 ;(
that did not help, i am getting the original image.
Should work. What values are you setting for each of the variables?
0

Yo can easyly resize image with Bitmap class, look at this constructor - http://msdn.microsoft.com/en-us/library/0wh0045z.aspx

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.