我正在开发 Android 安全应用程序,我必须锁定图库中的图像,因此我试图将图像从图库中移动到我的应用程序中。
我正在使用这段代码:
Cursor cursor = cursor1[0];
int i = 0;
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID));
long idC = Long.parseLong(id);
Uri newUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, idC);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(cr,newUri);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100,stream );
Bitmap compBit = Bitmap.createScaledBitmap(bitmap, 100,100, true);
bitmap1[i] = compBit;
bitmap.recycle();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
但得到这个异常:
Out of memory on a 4192360-byte allocation.
最佳答案
有一个关于有效显示位图的培训模块 - [链接] http://developer.android.com/training/displaying-bitmaps/index.html .
它提供了有关使用示例处理内存不足异常的良好信息。
关于android - 如何从图库中获取图像并在 Android 应用程序中移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17993970/