バイナリファイルがあります。1 つのデータは、8、16、32、64 ビットの符号付きおよび符号なし int にすることができます。テンプレート関数を作成しようとしていますが、これまでに行ったことは次のとおりです。
public T[] GetLayerBytes<T>(int LayerNum)
{
int typeSize = Marshal.SizeOf(typeof(T));
int layerPixelCount = typeSize * bitmapWidth * bitmapHeigth;
string recFileName = "my.rec";
using (FileStream fs = File.OpenRead(recFileName))
using (BinaryReader br = new BinaryReader(fs))
{
fs.Seek(layerPixelCount * LayerNum, SeekOrigin.Begin);
T[] b = new T[layerPixelCount];
//fs.Read(b, 0, layerPixelCount); this doesn't work
//br.Read(b, 0, layerPixelCount); this doesn't work too
return b;
}
}
C++ では、これにCFile::Readを使用します。
さまざまなタイプのスイッチ/ケースなしで試したのと同様に、bytes/int16/uint16 などを読み取る方法はありT
ますか?
すべての可能なエレガントなソリューションを事前に感謝します。