从SD卡中获取图像并将其存储在Android数据库中
答
是的,你可以从SD卡获取图像并将其存储在SQLite数据库,我们已经做到了,但它会为你的设备太昂贵了.......所以,要小心即,
呼叫通过调用图像拾取这个意图
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, 12);
它会打开默认的画廊选择器视图,当你选择,你会在你当前活动返回的图像,所以覆盖onActivityResult()
并查找结果代码12.
您可以通过这些线路
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
从这个光标对象获取光标,你可以通过这些线路
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
这里获取图像的文件路径为位图对象
Bitmap bMap = BitmapFactory.decodeFile(filePath);
Get byte arrays
ByteArrayOutputStream out = new ByteArrayOutputStream();
bMap.compress(Bitmap.CompressFormat.PNG, 100,out);
byte[] imageArray = out.toByteArray();
现在,您必须将imageArray作为blob存储在数据库中。你完成了....不要忘记从我从哪里得到的解决方案this post ...
其实我需要在我的应用程序中这样做的代码? – info 2011-04-07 06:06:18
检查我编辑的答案..... – Prasham 2011-04-07 06:27:54
感谢您的详细发布! – info 2011-04-07 08:20:53