我有一個JFIF格式的JPEG圖像。我想解碼它並獲得維度。解碼C#中的JFIF圖像文件
這裏是我的代碼:
while (binaryReader.ReadByte() == 0xff)
{
byte marker = binaryReader.ReadByte();
ushort chunkLength = binaryReader.ReadLittleEndianInt16();
if (marker == 0xc0)
{
binaryReader.ReadByte();
int height = binaryReader.ReadLittleEndianInt16();
int width = binaryReader.ReadLittleEndianInt16();
return new Size(width, height);
}
binaryReader.ReadBytes(chunkLength - 2);
}
確定。這段代碼很常見,你可以在互聯網上找到它。它適用於大多數JPEG圖像。
現在,相機拍攝的這個特定圖像 - 「Canon EOS 300D DIGITAL」不支持這段代碼。該維度的標記是0xFFC2而不是0xFFC0。
我的問題是哪一個是正確的?如果代碼正確,佳能相機如何產生非標準圖像?如果佳能相機是正確的,那麼我們如何修復代碼以正確找到此圖像的尺寸?
謝謝。
什麼是漸進式圖像?這是否意味着我們需要另一種方法來解碼漸進式jpeg圖像?我可以將if(marker == 0xc0) 更改爲if(marker == 0xc0 || marker == 0xc2)來解決問題嗎? – delpielo 2010-11-25 00:49:09