如何加載* .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