我有这样的图像/jped base64代码,
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA......
我需要,转换为图像此代码,并保存为jpeg文件的文件。我计算了Windows Form (C#)。插入到文本框和按钮。在textbox中插入base64代码(代码在上面),然后单击按钮。
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text))
{
string imageDataParsed = textBox1.Text.Substring(textBox1.Text.IndexOf(',') + 1);
byte[] imageBytes = Convert.FromBase64String(imageDataParsed);
MemoryStream ms1 = new MemoryStream(imageBytes);
Image img = Image.FromStream(ms1);
img.Save(Application.StartupPath + "\\Images\\1.jpg", ImageFormat.Jpeg);
}
}
文件另存为jpeg。但是这个文件在Windows照片查看器上看起来像这样
但是当我在Google Chrome这个64位的代码上运行时,没有任何问题。在Google Chrome浏览器上看起来很不错。
总结我的问题,我需要base64代码图像和保存这个文件我的服务器为jpeg文件。我该如何解决这个问题?谢谢。
发布于 2014-09-10 01:06:48
直接将Base64转换为文件避免将其加载到图像中,这样它应该像原始图像一样灵巧,当然这仍然不能解决图像显示问题。
byte[] newfile = Convert.FromBase64String(data);
File.WriteAllBytes(@"C:\path\to\file.jpg", newfile);
发布于 2014-09-10 00:55:40
我认为问题是大端和小端不匹配,请参阅http://en.wikipedia.org/wiki/Endianness
https://stackoverflow.com/questions/25748858
复制相似问题