简体   繁体   English

如何裁剪tiff图像的一部分

[英]How to crop a portion from tiff image

Here is my TIFF image and I am trying to extract left rectangle or box from the tiff image and save as a PNG file. 这是我的TIFF图像,我试图从tiff图像中提取左边的矩形或框并保存为PNG文件。

在此输入图像描述

the left side rectangle or box portion i tried to crop programmatically. 我试图以编程方式裁剪左侧矩形或框部分。 here is my routine. 这是我的惯例。

strImageFilePath = @"C:\Users\TRIDIP\Desktop\PDF\getLabel.tif";
var source = LoadImage(strImageFilePath);
Rectangle crop = new Rectangle(100, 160, 920, 1200);
var bmp = new Bitmap(920, 1200);
using (var gr = Graphics.FromImage(bmp))
{
  gr.DrawImage(source, new Rectangle(0, 0, bmp.Width, bmp.Height), crop, GraphicsUnit.Pixel);
  bmp.Save(@"C:\Users\TRIDIP\Desktop\PDF\Tile.png");
}

but the problem is coordinate calculation. 但问题是坐标计算。

Rectangle crop = new Rectangle(100, 160, 920, 1200);
var bmp = new Bitmap(920, 1200);

The value I gave above is not perfect and that is why the exact portion is not cropped. 我上面给出的值并不完美,这就是没有裁剪确切部分的原因。 so some one please download the image and tell me what top,left and height and width i should specify in my code as a result left box can be perfectly cropped from the image. 所以有人请下载图片并告诉我在我的代码中应该指定的顶部,左侧和高度和宽度,因此左侧框可以从图像中完美裁剪。 just help me to get the right coordinate means tell me exact figure for top, left and height and width. 只是帮助我获得正确的坐标意味着告诉我顶部,左侧和高度和宽度的确切数字。

Using paint this was really easy... 使用油漆这真的很容易......

X = 158, Y = 247, Width = 823, Height = 1183 X = 158,Y = 247,宽度= 823,高度= 1183

That is, 那是,

Rectangle crop = new Rectangle(158, 247, 823, 1183);
var bmp = new Bitmap(823, 1183);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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