如何加载* .tif图像的一部分而不将该图像加载到内存中。如何在不将整个图像加载到内存的情况下加载TIFF图像的一部分?
我必须使用大的TIFF文件。 (> 4 GB)。我尝试使用BinaryReader
读取此文件,并使用BitMiracle.LibTiff.Classic
将字节转换为图像。但是我没有找到如何读取TIFF文件中特定像素的示例。
也许你有这个任务的一些解决方案。
可以说我有一个BigScan.tif
文件,它始终是:
Image Compression - NONE
Pixel Order - Interleaved (RGBRGB)
Byte Order - IBM PC
我有一些变量:
ImagePart with User Defined Width
ImagePart with User Define Height
ImagePArt with User Defined Location
的问题是,我怎么能得到BigScan.tif
ImagePart
?
但是最好能够用(x,y)坐标系读取“BigScan.tif”中像素的信息。
我需要在指定的地方读取来自BigScan.tif
像素,具有这样的功能:
public Color GetPixelColorFromTiffImage(string TiffFileName, int PixelPositionX, int PixelPositionY)
{
//Some Code
return returnedColor;
}
很奇怪,但是支持did`t unswer我quastion。可能有人知道它。为什么要将这部分代码从BitMiracle Samples写入'raster'数组编号,如“-11512229”,“-11838376”等等。
using (Tiff image = Tiff.Open(fullImageLocation, "r"))
{
// Find the width and height of the image
FieldValue[] value = image.GetField(TiffTag.IMAGEWIDTH);
width = value[0].ToInt();
value = image.GetField(TiffTag.IMAGELENGTH);
height = value[0].ToInt();
int imageSize = height * width;
int[] raster = new int[imageSize];
// Read the image into the memory buffer
if (!image.ReadRGBAImage(width, height, raster))
{
MessageBox.Show("Could not read image");
}
using (Bitmap btm = new Bitmap(200, 200))
{
for (int i = 0; i < btm.Width; ++i)
for (int j = 0; j < btm.Height; ++j)
btm.SetPixel(i, j, getSample(i + 330, j + 30, raster, width, height));
ReternedBitmap = btm;
}
}//using
这有帮助吗? http://bitmiracle.com/libtiff/help/how-to-read-tiff-scanlines-in-a-random-fashion.aspx – 2013-04-30 09:32:07
嗯,我看到了这个页面。但我仍然想知道它是如何提供帮助的。如何使用它可以设置像素的位置,并从主tif文件中读取数据? – 2013-04-30 10:56:49
它允许您从图像中读取任意数量的scalines - 所以即使您必须采用全宽(x坐标),您至少可以选择一系列行(y坐标) - 也许这有助于吗? – 2013-04-30 11:22:17