简体   繁体   中英

How to programmatically crop image using c#

i have one pdf file which i will save first as image and then crop that image and save as cropped part as new image. i am not getting any idea how to crop the portion which i want.

here is url how our actual image will look like this

please click on the link and see what value i should provide to extract left rectangle. can you give me any idea.

i got code to crop a portion of image. here is one sample for cropping programmatically.

Rectangle cropRect = new Rectangle(...);
Bitmap src = Image.FromFile(fileName) as Bitmap;
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);

using(Graphics g = Graphics.FromImage(target))
{
    g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), 
                cropRect,                        
                GraphicsUnit.Pixel);
}

my concern is what value i should give here to crop the exact left rectangle from the image. Rectangle cropRect = new Rectangle(...);

can anyone give me any idea. thanks i got this code from this url How to crop an image using C#?

thanks

Since these labels are very standard, I wouldn't try to find out what to crop through code. Simply load your picture in a graphics editor which lets you know the coordinates of the mouse cursor (Paint.Net would be a good example) and find your Top, Left, Right and Bottom coordinates. "Hardcode" these values in your program and crop using them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM