我试图从图库中加载图像,但toSave.recycle()不起作用。我的意思是,当调用toSave.recycle()时,屏幕变白,应用程序不会崩溃,但图像不会显示。你有什么意见建议?
代码如下:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == LOAD_IMAGE_RESULT && resultCode == RESULT_OK && data != null) {
Uri pickedImage = data.getData();
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
postImage.setImageBitmap(bitmap);
saveImage(bitmap);
cursor.close();
}
}这里的方法转换位图图像并将其保存在Firebase中。
public void saveImage(Bitmap toSave){
if (toSave!=null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
toSave.compress(Bitmap.CompressFormat.JPEG, 50, stream);
toSave.recycle();
byte[] byteArray = stream.toByteArray();
String imageString = Base64.encodeToString(byteArray, Base64.DEFAULT);
simplepostRef.child("image").setValue(imageString);
}非常感谢!
发布于 2015-02-20 18:11:09
bitmap.recycle()正在处理你的案子。您不需要回收位图,因为您在docs中以imageview.Have的形式显示了这个位图。
https://stackoverflow.com/questions/28626280
复制相似问题