从相机拍摄的图像并不总是显示在我的ImageView
中。当它想要出现时似乎是随机的。为什么要这样做?
拍照的活动
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" />