How to load a part of a *.tif image without loading this image into memory.
I have to work with big TIFF files. (> 4 GB). I tried to read this file using BinaryReader
, and using BitMiracle.LibTiff.Classic
to convert bytes into image. But I didn't find example for how to read a specific pixel in a TIFF file.
Maybe be you have some solution for this task.
Lets say i have a BigScan.tif
file and it is always:
Image Compression - NONE
Pixel Order - Interleaved (RGBRGB)
Byte Order - IBM PC
I have some variable:
ImagePart with User Defined Width
ImagePart with User Define Height
ImagePArt with User Defined Location
The question is, how could I get ImagePart
from BigScan.tif
?
But it would be best to have the ability to read information of the pixel in "BigScan.tif" with (x,y) coorinates.
I need to read a pixel from the BigScan.tif
in specified place, with such function:
public Color GetPixelColorFromTiffImage(string TiffFileName, int PixelPositionX, int PixelPositionY)
{
//Some Code
return returnedColor;
}
Very strange but the support did`t unswer my quastion. May be somebody knows it. Why dose this part of the code from BitMiracle Samples wrote to 'raster' array numbers like "-11512229", "-11838376" and so on.
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