我试图简单地使用偏移量从一个 tiff 图像中选择图块并将它们写入另一个图像。我正在使用 libtiff.net。不是每个像素都有一个 ARGB 值,而是有一个像素是 alpha,然后右边的像素是红色像素,右边的像素是绿色的,当然右边的像素是蓝色的。我需要将这 4 个像素存储在一起,并且在此过程中发生了一些事情。你能看出这个逻辑有什么问题吗?
using (Tiff output = Tiff.Open(@"C:\base.tif", "w"))
{
if (output == null)
{
System.Console.Error.WriteLine("Could not open outgoing image");
return;
}
// We need to know the width and the height before we can malloc
int[] raster = new int[tileWidth * tileHeight];
// Write the tiff tags to the file
output.SetField(TiffTag.IMAGEWIDTH, 1024);
output.SetField(TiffTag.IMAGELENGTH, 1024);
output.SetField(TiffTag.TILEWIDTH, 256);
output.SetField(TiffTag.TILELENGTH, 256);
output.SetField(TiffTag.COMPRESSION, Compression.DEFLATE);
output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
output.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);
output.SetField(TiffTag.BITSPERSAMPLE, 8);
output.SetField(TiffTag.SAMPLESPERPIXEL, numOfBands);
byte[] inputBuffer = new byte[tileWidth * tileHeight * numOfBands];
// loop through every tile column
for (int x = 0; x < 1024 / tileWidth; x++)
{
// loop through every tile row in the current column
for (int y = 0; y < 1024 / tileHeight; y++)
{
image.ReadRGBATile((x + xOffset) * tileWidth, (y + yOffset) * tileHeight, raster);
Tiff.IntsToByteArray(raster, 0, raster.Length, inputBuffer, 0);
output.WriteEncodedTile(getTileIndex(x, y, 1024 / tileWidth), inputBuffer, 0, raster.Length);
}
}
}