以下代码,请用Bitmap替换Glide来实现同样的功能 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_IMAGE_CAPTURE) { Bitmap photo = (Bitmap) data.getExtras().get("data"); Uri tempUri = getImageUri(photo); selectedImagePath = tempUri.getPath(); Glide.with(this).load(tempUri).into(imageView); } else if (requestCode == REQUEST_IMAGE_PICK) { Uri selectedImageUri = data.getData(); selectedImagePath = selectedImageUri.getPath(); Glide.with(this).load(selectedImageUri).into(imageView); } } }
时间: 2024-02-14 10:25:16 浏览: 157
以下是使用Bitmap替换Glide的代码实现:
```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUEST_IMAGE_CAPTURE) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
Uri tempUri = getImageUri(photo);
selectedImagePath = tempUri.getPath();
imageView.setImageBitmap(photo);
} else if (requestCode == REQUEST_IMAGE_PICK) {
Uri selectedImageUri = data.getData();
selectedImagePath = selectedImageUri.getPath();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
```
在这个代码中,我们通过`setImageBitmap()`方法将Bitmap对象直接设置到ImageView中,而不是使用Glide库加载图片。对于拍摄的照片,我们直接使用`photo`作为Bitmap对象;对于从相册选择的照片,我们使用`MediaStore`来获取Bitmap对象。
阅读全文