【发布时间】:2023-03-19 22:55:01
【问题描述】:
当我点击打开相机的弹出窗口时。如果我拍摄保存良好的照片。
但如果我只进入相机并退出而不添加照片,则图像会像给定的图片一样保存。
.
- 如果添加任何新图像,则所有损坏的图像都将替换为新图像,例如第二张图像
.
这是用来拍照的
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals(getString(R.string.label_popup_takephoto))) //take photo
{
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri mPhotoUri;
if(bal.hasStorage(true))
mPhotoUri = getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
else
mPhotoUri = getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, new ContentValues());
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoUri);
startActivityForResult(takePhotoIntent, 1);
}
这是用于存储的图像
if (resultCode == -1) {// Camera
Bitmap addphoto = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.user);
if (requestCode == 1) {
Cursor cursor;
String imagePath = null;
cursor = getActivity().getContentResolver().query(Media.EXTERNAL_CONTENT_URI,
new String[] { Media.DATA, Media.DATE_ADDED,MediaStore.Images.ImageColumns.ORIENTATION },Media.DATE_ADDED, null, "date_added ASC");
if (cursor != null && cursor.moveToFirst()){
do
{
imagePath = cursor.getString(cursor.getColumnIndex(Media.DATA));
}while(cursor.moveToNext());
}
cursor.close();
Bitmap yourSelectedImage=processimage(imagePath);
//Bitmap yourSelectedImage = getScaledBitmap(imagePath, 500, 500);
if (yourSelectedImage != null) {
if (imgprofile != null) {
imgprofile.setImageBitmap(yourSelectedImage);
picimagepath=imagePath;
bmp=yourSelectedImage;
}
else{
imgprofile.setImageBitmap(addphoto);
}
}
Hase 存储
public boolean hasStorage(boolean requireWriteAccess)
{
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
} else if (!requireWriteAccess
&& Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
我的错误在哪里?
【问题讨论】:
-
与论坛网站不同,我们不使用“谢谢”、“任何帮助表示赞赏”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?。顺便说一句,这是“提前致谢”,而不是“致谢”。
标签: android