gpt4 book ai didi

android - 无法预览捕获的高质量图像

转载 作者:行者123 更新时间:2023-11-30 05:05:34 24 4
gpt4 key购买 nike

我正在关注 android developers guide捕获高质量图像并将其保存到存储器中然后显示它。问题是在捕获图像后我被重定向到主要 Activity 而不显示预览尽管图像已在存储中成功创建

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);
}
}

最佳答案

将图像路径保存为 currentImagePath 变量中的字符串

private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);

// Save a file: path for use with ACTION_VIEW intents
currentImagePath = image.getAbsolutePath();
return image;
}

然后显示预览

Bitmap bitmap = BitmapFactory.decodeFile(currentImagePath);
HQimageView.setImageBitmap(bitmap);

关于android - 无法预览捕获的高质量图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54651827/

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