c# - 从 sqlite 数据库下载 byte[] 并转换为照片
问题描述
我在将 byte [] 从 SQLITE 数据库转换为照片时遇到问题。
public List<Tuple<string, Tuple<byte[], byte[]>>> GetNameAndImagesPositions()
{
sqlite_conn = new SQLiteConnection(conn);
sqlite_conn.Open();
sqlite_cmd = sqlite_conn.CreateCommand();
sqlite_cmd.CommandText = "SELECT NAME, IMG_BALCONY, IMG_CROSS FROM MAIN";
sqlite_datareader = sqlite_cmd.ExecuteReader();
List<Tuple<string, Tuple<byte[], byte[]>>> res = new List<Tuple<string, Tuple<byte[], byte[]>>>();
while (sqlite_datareader.Read())
{
Tuple<string, Tuple<byte[], byte[]>> tup = new Tuple<string, Tuple<byte[], byte[]>>(sqlite_datareader.GetString(0),
new Tuple<byte[], byte[]>(
(byte[])sqlite_datareader["IMG_BALCONY"],
(byte[])sqlite_datareader["IMG_CROSS"]));
res.Add(tup);
}
sqlite_conn.Close();
return res;
}
在数据库中,照片(byte [])存储在 BLOB 中。
DatabasePositions dbp = new DatabasePositions();
List<Tuple<string, Tuple<byte[], byte[]>>> list = new List<Tuple<string, Tuple<byte[], byte[]>>>();
list = dbp.GetNameAndImagesPositions();
for (int i = 0; i < list.Count; i++)
{
foreach (var elm in list)
{
string nameFile1 = elm.Item1 + "(1)";
string nameFile2 = elm.Item1 + "(2)";
Uri pat = new Uri(Directory.GetCurrentDirectory() + "\\report\\img\\" + nameFile1 + ".png");
using (FileStream outStream = new FileStream(pat.LocalPath, FileMode.Create))
{
var ms = new MemoryStream(elm.Item2.Item1);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(ms));
encoder.Save(outStream);
}
}
}
错误:在行encoder.Frames.Add(BitmapFrame.Create(ms));
System.NotSupportedException: "The appropriate image processing component needed to perform this operation was not found
我怀疑从数据库转换字节 [] 有问题。原因是byte[]之前在数据库中工作正常,但是从数据库中下载之后就不行了。
解决方案
推荐阅读
- javascript - 如何在类似于 chrome 的网络面板的 javascript 中记录页面/url 上的 http 请求?
- python - 谷歌日历 service.events().list 不返回事件
- ios - UIButton:容器中的文本居中,图像左侧
- c - 如何在我的实现 QuickSort 中防止 stackoverflow?
- javascript - 使用 ajax 的相同代码的不同输出。为什么?
- regex - 在 unix shell 脚本中的两个单词之间找到一个单词
- c++ - 我的程序太慢了
- docker - 为 gcloud 构建提交指定 Dockerfile
- amazon-web-services - 限制对 Redshift 表的访问,仅授予对视图的访问权限
- reactjs - 在 Gatsby 中使用 react-web-vector-icons 时出现“无法从...解码字体”错误