C# 从sqlite数据库下载字节[],并转换为照片
我在将字节[]从SQLITE数据库转换为照片时遇到问题C# 从sqlite数据库下载字节[],并转换为照片,c#,sqlite,C#,Sqlite,我在将字节[]从SQLITE数据库转换为照片时遇到问题 public List<Tuple<string, Tuple<byte[], byte[]>>> GetNameAndImagesPositions() { sqlite_conn = new SQLiteConnection(conn); sqlite_conn.Open(); sqlite_cmd = sqli
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;
}
我怀疑从数据库转换字节[]时出错。原因是在数据库中工作之前,字节[]可以正常工作,但从数据库中下载之后就不再工作了。您使用的是
Tuple
,为什么不创建具有该结构的类呢?是否每个照片都会失败?@l0ui适用于数据库中的每个人。当我应用直接获得的字节[]时,它工作正常。
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);
}
}
}
System.NotSupportedException: "The appropriate image processing component needed to perform this operation was not found