Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将图像保存到SQLITE?_Android_Sqlite - Fatal编程技术网

Android 将图像保存到SQLITE?

Android 将图像保存到SQLITE?,android,sqlite,Android,Sqlite,我应该使用哪种数据类型在sqlLite数据库表中存储图像 以下是我的尝试: @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL("CREATE TABLE" + MP_TABLE_NAME + " ( " + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT

我应该使用哪种数据类型在sqlLite数据库表中存储图像

以下是我的尝试:

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL("CREATE TABLE" + MP_TABLE_NAME + " ( " +
            BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            " NAME TEXT, " +
            " LAT REAL, "+
            " LNG REAL,"+
            ");"
              );

}
请参阅

您可能需要一个BLOB类型,也称为二进制BLOB或二进制长对象。请注意,在SQLite数据库中存储非常大的内容并不一定是一个好主意—如果您能够管理图像,通常最好将其存储在文件系统中。

请参阅


您可能需要一个BLOB类型,也称为二进制BLOB或二进制长对象。请注意,在SQLite数据库中存储非常大的内容并不一定是一个好主意-如果您能够管理它,通常最好将图像存储在文件系统中。

将图像保存到SQLite中是一个坏主意。您应该将其路径保存到sqlite中。与文本信息相比,图像的大小更大

从sqlite保存和检索图像是很困难的


所以,我建议您将图像存储在外部文件夹中,并将其路径存储到sqlite数据库中。

将图像保存到sqlite是个坏主意。您应该将其路径保存到sqlite中。与文本信息相比,图像的大小更大

从sqlite保存和检索图像是很困难的

因此,我建议您将图像存储在外部文件夹中,并将其路径存储在sqlite数据库中。

试试这个

创建具有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));
试试这个

创建具有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));

您应该将图像存储在SD卡上,并在数据库中存储图像的路径。将图像保存到内部/外部内存并仅在数据库中保存对它们的一些引用不容易吗?您应该将图像存储在SD卡上,并在数据库中存储图像的路径。将图像保存到内部/外部内存并不容易请给我一个如何将图像保存到文件夹中的示例?请给我一个如何将图像保存到文件夹中的示例?请给我一个如何将图像保存到文件夹中的示例?请给我一个示例?