我使用as3 PNGencoder(https://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/images/PNGEncoder.as?r=25) 我把它发送到我的服务器,我收到了一个巨大的字节[6763]
我试图用这个获得图像:
int Lenght = Request.RemainingLength;
byte[] t = Request.ReadBytes(Request.RemainingLength);
string k = Convert.ToBase64String(t);
Image image;
using (MemoryStream ms = new MemoryStream(t))
{
image = Image.FromStream(ms);
}
但它总是给我错误:参数无效
我也尝试将它转换为base64字符串并得到了这个,但它也说它不是一个有效的图像(k),并且继承了在Convert.ToBase64String()之后K的base64:
AAAaZ4lQTkcNChoKAAAADUlIRFIAAAFAAAABQAgGAAAAzZClqgAAGi5JREFUeNrtnV2oZtdZx7e1NtUghExpUdDWaRwxNvZjNI1YKhMtY1SQ5KakKYOIsfGqaefCNkQTWg1UIYRMpp1U2jKCyUUKQnITSUfwAyM4tBcVJAqCFyL2nJnMmI82xLB9n33Oel1nn/2x9t5r7fWstX4DP86c877ved919t4/nr0+/qt65NGv1kNUVQUAkCcIEAAQIAIEAASIAAEAASJAAECAAAAIEAAAAQIAIEAAAAQIAIAAAQAQIAAAAgQAQIAAAAgQAAABAgAgQAAABAgAgAABABAgAAACBABAgAAACBAAAAECACBAAAAECACAAAEAECAAAAIEAECAAIAAESAAIEAECAAIEAECAAJEgACAAAEAECAAAAIEAECAAAAIEAAAAQIAIEAAAAQIAIAAAQAQIAAAAgQAQIAAAAgQAAABAgAgQAAABAgAgAABABAgAAACBABAgAAACBAAAAECACBAAAAECACAAAEAASJAAECACBAAECACBAAEyB8JABAgAAACBABAgAAACBAAAAECACBAAAAECACAAAEAECAAAAIEAECAAAAIEAAAAQIAIEAAAAQIAIAAAQAQIAAAAgQAQIAAAAgQAAABAgAgQAAABAgAgAABABAgACBABAgACBABAgACRIAAgAABABAgAAACBABAgAAACBAAAAECACBAAAAECACAAAEAECAAAAIEAECAAAAIEAAAAQIAIEAAAAQIAIAAAQAQIAAAAgQAQIAAAAgQAAABAgAgQAAABAgAgAABAAEiQ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GvvSqddfKXk8a0hviF/qNgTpOR5cGPP6RJgTiKMvS+xVvGVkscXe61w1D1BSl4JsaQCzEGEvlfC5Ca+UvL4YvcxRtkTpOS1sEv6AHMQYei10LmIr5Q8vth9jKvuCVJyGsqSUeAQG3znJL4UREge320q+xhX2ROk5Dy8pa+fI0BNIkz5708eX/g8vrHPF/rvH3RPkJLz+Mz/jYyWzoNbusF3ifKJ+VnI47vNWx/jkvcfFWCIPUFKzuNr/6wto6Xz4LSLMOU+WPL41p/OMqWPcc77jwrQ554gJefx9T3WJ6Ol8+C0iTDlUXjy+OLN45vTxzjl/Z0qwKV7gpScxzf2nDEZLX3/2CIkj488Ps3vPypAuRDm7glSch6f63NdJDSnjzC2CMnjI6Qghz7Gyr4QXPcEKTmPb+rvdBXg3MGStUVIHh/iy6mPseq6EPr2BCk5j2/u75oqQK0iJI8P8eXYx1gNXQiliS/ERT9XgFpESB4f4ovZ/tDirVwugtLy6HzM43MVoetE51giLDWPkDy+dfL4Ylec1ZQKJfcLwcc8vqkinLrSY20RlpZHSB7funl8sW+1/w+Zw4FlfXjQrQAAAABJRU5ErkJggg==
所以什么错了?因为我真的不知道!我需要跳过一些字节吗?或者什么是base64的错误?因为它从gPNG开始看起来正确......
答案 0 :(得分:0)
"do i need to skip some bytes? or whats wrong with the base64? because it starts with gPNG"
是.. !!你非常接近答案,你应该相信你的“编码”本能更多。无论如何你应该进行实验。如有疑问,请使用十六进制编辑器检查“无效图像”字节。
你基于64字符串给出这样的字节:(十六进制)
00 00 1A 67 89 50 4E 47
. . . g ‰ P N G
如果你删除前四个字节:00 00 1A 67
你只有89 50 4E 47
以后会给出一个有效的PNG头开始字节‰PNG etc etc
(其他一切对你的字节都没问题)。
这是什么造成的?
A)我只能猜测你是从一个较大的字节集中提取PNG,并以某种方式从实际图像起始字节的负4的偏移中获取?或者重用一个已经保存了这四个字节字节的字节数组,并且你要向它添加PNG字节?
B)您的PHP或服务器正在编辑字节?有一些自定义标头字节?
无论如何,你只需要一个“显示前清理”的功能,它只需要修剪前四个字节。