C# 如何在windows应用商店应用程序中将图像添加到sqlite?

C# 如何在windows应用商店应用程序中将图像添加到sqlite?,c#,xaml,windows-store-apps,C#,Xaml,Windows Store Apps,我想在windows应用商店应用程序中使用SQLite创建一个用于图像处理的应用程序。 我正在尝试将图像存储到SQLite中,并从SQLite中检索图像。为了存储图像,我尝试将图像从xaml控件图像源转换为字节数组,但不起作用 windows应用商店应用程序中的图像到字节数组转换有什么建议吗 这段代码是用JAVA编写的,但u可以转换成C# 创建具有BLOB列的表: CREATE TABLE storedImages (_id INTEGER PRIMARY KEY, myImage BLOB);

我想在windows应用商店应用程序中使用SQLite创建一个用于图像处理的应用程序。 我正在尝试将图像存储到SQLite中,并从SQLite中检索图像。为了存储图像,我尝试将图像从xaml控件图像源转换为字节数组,但不起作用


windows应用商店应用程序中的图像到字节数组转换有什么建议吗

这段代码是用JAVA编写的,但u可以转换成C#

创建具有BLOB列的表:

CREATE TABLE storedImages (_id INTEGER PRIMARY KEY, myImage BLOB);
使用HTTP下载图像并将其存储在表中:

DefaultHttpClient mHttpClient = new DefaultHttpClient();  
HttpGet mHttpGet = new HttpGet("your image url");  
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);  
if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
    HttpEntity entity = mHttpResponse.getEntity();  
    if (entity != null) {  
    // insert to database  
    ContentValues values = new ContentValues();  
    values.put(MyBaseColumn.MyTable.ImageField, EntityUtils.toByteArray(entity));  
    getContentResolver().insert(MyBaseColumn.MyTable.CONTENT_URI, values);  
 }
}
将BLOB加载到ImageView中:

ImageView myImage = (ImageView) findViewById(R.id.myImage);
byte[] bb = cursor.getBlob(cursor.getColumnIndex(MyBaseColumn.MyTable.ImageField));
myImage.setImageBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));
编辑:1

有关c#中的更多参考信息,请参见下面的链接


我想将xaml图像控件中的图像存储到sqlite中,在windows应用商店应用程序sqlite中,没有Blob类型,我使用的是byte[]类型