首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓bitmap.recycle()无法工作

安卓bitmap.recycle()无法工作
EN

Stack Overflow用户
提问于 2015-02-20 18:06:01
回答 1查看 471关注 0票数 0

我试图从图库中加载图像,但toSave.recycle()不起作用。我的意思是,当调用toSave.recycle()时,屏幕变白,应用程序不会崩溃,但图像不会显示。你有什么意见建议?

代码如下:

代码语言:javascript
复制
@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中。

代码语言:javascript
复制
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);
    }

非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2015-02-20 18:11:09

bitmap.recycle()正在处理你的案子。您不需要回收位图,因为您在docs中以imageview.Have的形式显示了这个位图。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28626280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档