从相机拍摄的图像并不总是显示在我的 ImageView
中。它想出现的时候似乎是随机的。为什么要这样做?
拍照的Activity
private void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_PICTURE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String spokenText;
// Handles picture taking after finished
if (requestCode == REQUEST_PICTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap image = (Bitmap) extras.get("data");
ImageView imageResult = (ImageView) findViewById(R.id.result_image);
imageResult.setImageBitmap(image);
ImageHandler imageHandler = new ImageHandler(this);
imageHandler.writeToFile(image, step.getChecklistId(), step.getOrder());
step.setImageFilename(imageHandler.getFilename(step.getChecklistId(), step.getOrder()));
finishStep();
}
}
显示图片的XML
<ImageView
android:id="@+id/result_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:contentDescription="@string/taken_img_desc" />
最佳答案
您是否为您的适配器使用了 notifyDataSetChanged? 你的观点被刷新了吗?试试 .invalidate();
关于android - 从拍摄的照片中放入 ImageView 的图像并不总是显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21246870/