1
將透明PNG圖像下載到圖像列表中時,直接將它們放入列表視圖中的質量很高。從SQLite數據庫保存和檢索png?
但現在我試圖將圖像保存到SQLite數據庫中,並以相同的高質量恢復它們,但是我嘗試的所有內容都很差。
我嘗試了SQLite字段類型的IMAGE,CHAR和BLOB以及各種方法來獲取數據。有沒有最好的字段類型?
我試着將它保存爲位圖,但我找不到如何將其轉換回透明png。也許這會工作?
這是我用CHAR字段類型試過的最後一件事。當我將它添加到圖像列表時,質量非常差(dr是SQLite數據行)。
byte[] imageBytes = Convert.FromBase64String(dr["image"].ToString());
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
可有人請告訴我如何透明PNG保存爲SQLite的高質量圖像,並把它背出在相同的高品質?
感謝
編輯
我可以保存爲BMP與此:
string base64ImageString = ImageToBase64(imageList1.Images[i], ImageFormat.bmp);
但不知道如何把它找回來了作爲一個透明的PNG,
編輯
真正的問題是我失去了透明度。那些部分現在是黑色的。
我用這一點,但它似乎並沒有幫助:
byte[] imageBytes = Convert.FromBase64String(dr["image"].ToString());
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
using (MemoryStream mss = new MemoryStream())
{
bmp.Save(ms, ImageFormat.Png);
}
SQLite不會更改blob的內容。你如何將圖像保存到數據庫中? –
'ImageToBase64'的代碼是什麼?該方法將有一些注意事項。 –
我目前使用: string base64ImageString = ImageToBase64(imageList1.Images [i],ImageFormat.Bmp); 請看我最新的編輯 – dnennis