IT Community - Software Programming, Web Development and Technical Support

Image Croping in C# .net

This is a discussion on Image Croping in C# .net within the C# Programming forums, part of the Software Development category; Image Croping in C# .net Hi Guys, how to do the Image Croping in C#. Thanks in advance....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-17-2007, 12:14 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Image Croping in C# .net

Image Croping in C# .net


Hi Guys,

how to do the Image Croping in C#.

Thanks in advance.

Last edited by oxygen : 07-30-2007 at 06:38 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 06:39 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Image Croping in C# .net

Hi its very simple,

Steps:

1. Create a windows class library project

2. Add the below method to the project
using System;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

public static Image ImageCrop(Image image, int left, int top, int width, int height)
{
Bitmap newImage = new Bitmap(width, height);
Graphics g = Graphics.FromImage(newImage);
newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
g.DrawImage(image, new Rectangle(0, 0, cropWidth, cropHeight), new Rectangle(left, top, width, height), GraphicsUnit.Pixel);
return (Image)newImage;
}

3. You can call this method like this

Image myImage = System.Drawing.Image.FromFile(imageFileName);
myImage = ImageCrop(myImage,0,0,1024,768);
myImage.Save(newImageFileName, ImageFormat.Jpeg);

Hope informative,
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-30-2008, 05:09 AM
orzchrs orzchrs is offline
D-Web Trainee
 
Join Date: Sep 2008
Posts: 2
orzchrs is on a distinguished road
Default Re: Image Croping in C# .net

include the system.IO use the file objecet
__________________
flyers printing
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DPI of an Image Anandavinayagam C# Programming 6 12-12-2008 05:53 AM
Convert image to other image format using CODEC in .NET 3.0 Mramesh C# Programming 0 02-07-2008 03:33 AM
How to create an image from panel background Image S.Vinothkumar C# Programming 1 10-22-2007 03:52 AM
How to upload an image to DB in ASP.Net? mobilegeek ASP and ASP.NET Programming 6 09-18-2007 11:18 PM
Rotating an Image muthukumar HTML, CSS and Javascript Coding Techniques 1 07-30-2007 03:18 AM


All times are GMT -7. The time now is 05:18 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0