gpt4 book ai didi

android - 从 ImageView 中删除/移除当前图像?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:41 29 4
gpt4 key购买 nike

每次用户再次单击以将另一个图像设置到 imageView 时,我都想从 imageView 中删除/删除或清除图像。我收到 OutOfMemoryError:位图大小超出 VM 预算(堆大小=7239KB,分配=2769KB,位图大小=8748KB) 这是我的代码:

ImageView imageView;
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
Bitmap yourSelectedImage;



@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


}


@Override
protected void onResume() {
super.onResume();
imageView = (ImageView) findViewById(R.id.imageView);

((ImageView) findViewById(R.id.imageView))
.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

goToGallery();
}
});

}


public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
/*Toast.makeText(getBaseContext(), "" + selectedImagePath, 1000)
.show();
*///editText2.setText(selectedImagePath);

// Convert file path into bitmap image using below line.
yourSelectedImage = BitmapFactory
.decodeFile(selectedImagePath);

// put bitmapimage in your imageview
imageView.setImageBitmap(yourSelectedImage);


}
}
}

public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
private void goToGallery()
{


// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
SELECT_PICTURE);

}

最佳答案

将资源设置为 0 对我不起作用。以下确实有效:

imageView.setImageBitmap(null);

关于android - 从 ImageView 中删除/移除当前图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8326347/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com