2014-07-20 2 views
0

RAW 이미지를로드하는 기능에 문제가 있습니다. 오류의 원인을 이해할 수 없습니다. 그것은 나에게 오류를 보여줍니다암시 적으로 'int'형식을 LittleEndian으로 변환 할 수 없습니다. ByteOrder

Cannot implicitly convert type 'int' to 'Digital_Native_Image.DNI_Image.Byteorder'

public void load_DNI(string ficsrc) 
{ 
    FileStream FS = null; 
    BinaryReader BR = null; 
    int width = 0; 
    int height = 0; 
    DNI_Image.Datatype dataformat = Datatype.SNG; 
    DNI_Image.Byteorder byteformat = Byteorder.LittleEndian; 

    FS = new FileStream(ficsrc, System.IO.FileMode.Open); 
    BR = new BinaryReader(FS); 

    dataformat = BR.ReadInt32(); 
    byteformat = BR.ReadInt32(); 
    width = BR.ReadInt32(); 
    height = BR.ReadInt32(); 

    // fermeture des fichiers 
    if ((BR != null)) 
     BR.Close(); 
    if ((FS != null)) 
     FS.Dispose(); 

    // chargement de l'_image 
    ReadImage(ficsrc, width, height, dataformat, byteformat); 
} 

답변

1

int의의 암시 적 enum로 변환 할 수 없습니다 '의. 여기에 명시적인 캐스트를 추가해야합니다.

dataformat = (Datatype.SNG)BR.ReadInt32(); 
byteformat = (Byteorder)BR.ReadInt32(); 

자세한 내용은 Casting and Type Conversions (C# Programming Guide)을 읽으십시오.

그러나 if (BR != null) 검사는 필요하지 않으며 실제로는 IDisposable 개체를 처리하는 올바른 방법이 아닙니다. 이 코드를 다시 작성하여 using blocks을 사용하는 것이 좋습니다. 이 FSBR가 제대로 배치 얻을 수 있도록합니다

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); 

그러나 같은 BinaryReader를 사용하는 ReadImage 방법을 리팩토링하여이 더 향상시킬 수있는 것처럼도 보인다. 그런 다음이 방법을 다음과 같이 다시 작성하십시오.

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); 
}