Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法隐式转换类型';int';小印度字节顺序_C#_Binaryreader - Fatal编程技术网

C# 无法隐式转换类型';int';小印度字节顺序

C# 无法隐式转换类型';int';小印度字节顺序,c#,binaryreader,C#,Binaryreader,我加载原始图像的函数有问题。我不明白错误的原因。它向我显示了以下错误: 无法将类型“int”隐式转换为“Digital\u Native\u Image.DNI\u Image.Byteorder” int不能隐式转换为enum。您需要在此处添加显式强制转换: dataformat = (Datatype.SNG)BR.ReadInt32(); byteformat = (Byteorder)BR.ReadInt32(); 阅读了解更多信息 但是,请注意,if(BR!=null)检查是不必要的

我加载原始图像的函数有问题。我不明白错误的原因。它向我显示了以下错误:

无法将类型“int”隐式转换为“Digital\u Native\u Image.DNI\u Image.Byteorder”


int
不能隐式转换为
enum
。您需要在此处添加显式强制转换:

dataformat = (Datatype.SNG)BR.ReadInt32();
byteformat = (Byteorder)BR.ReadInt32();
阅读了解更多信息

但是,请注意,
if(BR!=null)
检查是不必要的,这确实不是处理对象的正确方法。我建议您重写此代码以便使用。这将确保
FS
BR
得到正确处置:

int width;
int height;
Datatype dataformat;
Byteorder byteformat;

using (var FS = FileStream(ficsrc, System.IO.FileMode.Open))
using (var BR = new BinaryReader(FS))
{

    dataformat = (Datatype.SNG)BR.ReadInt32();
    byteformat = (Byteorder.LittleEndian)BR.ReadInt32();
    width = BR.ReadInt32();
    height = BR.ReadInt32();
}

// chargement de l'_image
ReadImage(ficsrc, width, height, dataformat, byteformat);
但是,通过重构
ReadImage
方法以使用相同的
BinaryReader
,您似乎可以进一步改进这一点。然后您可以重写此方法,使其看起来更像:

using (var FS = FileStream(ficsrc, System.IO.FileMode.Open))
using (var BR = new BinaryReader(FS))
{

    var dataformat = (Datatype.SNG)BR.ReadInt32();
    var byteformat = (Byteorder.LittleEndian)BR.ReadInt32();
    var width = BR.ReadInt32();
    var height = BR.ReadInt32();
    ReadImage(ficsrc, width, height, dataformat, byteformat, BR);
}
using (var FS = FileStream(ficsrc, System.IO.FileMode.Open))
using (var BR = new BinaryReader(FS))
{

    var dataformat = (Datatype.SNG)BR.ReadInt32();
    var byteformat = (Byteorder.LittleEndian)BR.ReadInt32();
    var width = BR.ReadInt32();
    var height = BR.ReadInt32();
    ReadImage(ficsrc, width, height, dataformat, byteformat, BR);
}