C# base64编码转成图片
File.WriteAllBytes(@"c:\yourfile", Convert.FromBase64String(yourBase64String));//将base64编码转成图片
读取mysql blob类型的字段
while (reader.HasRows) { if (reader.Read()) { //读取blob类型的字段 long len = reader.GetBytes(3, 0, null, 0, 0);//3为blob字段的索引(索引从0开始算) byte[] buffer = new byte[len]; len = reader.GetBytes(3, 0, buffer, 0, (int)len); string content = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length); File.WriteAllBytes(path + DateTime.Now.Ticks.ToString() + ".jpeg", Convert.FromBase64String(content));//将base64转成图片 } else { break; } }
一行代码就OK了。