这是我的问题。忍受我给一点点解释:byte [] to ushort []
我正在阅读tiff图像到缓冲区;我的tiff的每个像素都由一个ushort(16位数据,非负)表示。
我的图像大小是64 * 64 = 4096.当我的tiff被加载到缓冲区时,缓冲区长度因此是8192(两倍于4096)。我想这是因为在我的缓冲区中,计算机使用2个字节来存储单个像素值。
我想获得任何特定像素的值,在这种情况下,我应该结合每2个字节1 ushort?
例如:00000000 11111111 - > 0000000011111111?
这里是我的代码:
public static void LoadTIFF(string fileName, int pxlIdx, ref int pxlValue)
{
using (Tiff image = Tiff.Open(fileName, "r"))
{
if (image == null)
return;
FieldValue[] value = image.GetField(TiffTag.IMAGEWIDTH);
int width = value[0].ToInt();
byte[] buffer = new byte[image.StripSize()];
for (int strip = 0; strip < image.NumberOfStrips(); strip++)
image.ReadEncodedStrip(strip, buffer, 0, -1);
// do conversion here:
//ushort bufferHex = BitConverter.ToUInt16(buffer, 0);
image.Close();
}
}
我如何读取字节[]缓冲区,以确保我能得到16位USHORT像素值?
由于
是的,我想我得到了我想要的像素。非常感谢! – 2013-02-13 17:10:04
尽管偏移看起来是2的乘法,而y实际上是(y-1),并且对于x也是一样的。那么取决于基于0或1的索引。 – 2013-02-21 01:13:34