轉換的圖像時出現「參數無效」錯誤當前我正在測試一個腳本,該腳本嘗試保存從HEX字符串轉換而來的圖像文件,但是,當我嘗試執行保存命令時,參數無效出現。嘗試保存從字節
// Some junk hex image data
string hexImgData = @"FFD8FFE000104A46494600010200006400640000FFFFD9";
// Call function to Convert the hex data to byte array
byte[] newByte = ToByteArray(hexImgData);
MemoryStream memStream = new MemoryStream(newByte);
// Save the memorystream to file
Bitmap.FromStream(memStream).Save("C:\\img.jpg");
// Function converts hex data into byte array
public static byte[] ToByteArray(String HexString)
{
int NumberChars = HexString.Length;
byte[] bytes = new byte[NumberChars/2];
for (int i = 0; i < NumberChars; i += 2)
{
bytes[i/2] = Convert.ToByte(HexString.Substring(i, 2), 16);
}
return bytes;
}
目前我還在尋找是什麼原因造成的,請指教。
您確定'hexImgData'有效的'BitMap'內容嗎? 我的意思是[語法和結構](http://en.wikipedia.org/wiki/JPEG) – 2013-05-07 03:07:53