微信图片解决方法-windows版的dat文件
public string decodeImg(string filepath)
{
Dictionary<string, byte[]> headers = new Dictionary<string, byte[]>
{
{ "jpg", new byte[]{ 0xff, 0xd8 }},
{ "png", new byte[]{ 0x89, 0x50 }},
{ "gif", new byte[]{ 0x47, 0x49 }},
};
for (int i = 0; i < 10; i++)
{
try
{
byte[] buf = File.ReadAllBytes(filepath);
foreach (string encoding in headers.Keys)
{
byte header_code = headers[encoding][0];
byte check_code = headers[encoding][1];
byte magic = do_magic(header_code, buf);
byte code = (byte)(buf[1] ^ magic);
if (check_code == code)
{
byte[] outbytes = decode(magic, buf);
string outpath = filepath.Replace("dat", encoding);
File.WriteAllBytes(outpath, outbytes);
return outpath;
}
}
break;
}
catch (FileNotFoundException ex)
{
Thread.Sleep(1000);
}
}
return null;
}
微信开发SDK-联系QQ:3209-66311