圖像存儲在我的SQLite數據庫中,我需要將用戶選擇的圖像附加到電子郵件/ mms應用程序。但是這樣的應用程序只能通過URI格式(Intent.EXTRA_STREAM
)接受圖像,而不是直接接收字節數組/圖像本身。存儲在SQLite數據庫中的圖像的URI
所以現在我需要存儲在SQLite數據庫中的圖像的URI。我如何檢索它? 或者我需要爲我的自定義內容提供者編寫它嗎?
圖像存儲在我的SQLite數據庫中,我需要將用戶選擇的圖像附加到電子郵件/ mms應用程序。但是這樣的應用程序只能通過URI格式(Intent.EXTRA_STREAM
)接受圖像,而不是直接接收字節數組/圖像本身。存儲在SQLite數據庫中的圖像的URI
所以現在我需要存儲在SQLite數據庫中的圖像的URI。我如何檢索它? 或者我需要爲我的自定義內容提供者編寫它嗎?
聽起來好像是你需要編寫自己的內容提供商,如你所提到的 - 沒有之一,因此,操作系統沒有辦法你的數據庫與URI
此代碼爲我交往。你可以得到適當的解決方案
Uri selectedImage = data.getData();
ImageView imageView=(ImageView)this.findViewById(R.id.imageView1);
getContentResolver().notifyChange(selectedImage, null);
ContentResolver cr = getContentResolver();
Bitmap bitmap;
try {
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
imageView.setImageBitmap(bitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(encodedImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,
bytarray.length);
myDb.execSQL("INSERT INTO imgtbl VALUES('"+encodedImageString+"');");
Cursor c= myDb.rawQuery("SELECT * FROM imgtbl", null);
c.moveToFirst();
String img=c.getString(0);
byte[] byarray = Base64.decode(img, Base64.DEFAULT);
Bitmap bmimg = BitmapFactory.decodeByteArray(byarray, 0,
byarray.length);
ImageView iv=(ImageView)findViewById(R.id.img2);
ImageView iv1=(ImageView)findViewById(R.id.img3);
iv.setImageBitmap(bmimg);
iv1.setImageBitmap(bmimg);
} catch (Exception e) {
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
.show();
e.printStackTrace();
}
是不是隻是一個字符串的URI?將其存儲在表格的另一個字段中。 – 2012-03-29 17:28:25