【发布时间】:2019-02-12 14:03:36
【问题描述】:
我正在关注android developers guide 以捕获高质量图像并将其保存到存储中然后显示。问题是在捕获图像后我被重定向到主要活动而不显示预览,尽管图像已在存储中成功创建
public void take_hq_image(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, HIGH_Q_IMAGE_CAPTURE_REQUEST);
}
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == HIGH_Q_IMAGE_CAPTURE_REQUEST && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap bitmap = (Bitmap) extras.get("data");
HQimageView.setImageBitmap(bitmap);
}
}
【问题讨论】:
-
您正在使用
EXTRA_OUTPUT。结果,返回的Intent中没有额外的"data"。你的图片应该在photoFile——从那里加载它。见this sample app。 -
是HQimageView.setImageBitmap(bitmap);相机完成时调用? HQimageView 初始化了吗?
标签: android android-camera image-capture