久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MediaStore.EXTRA_OUTPUT 呈現數據為空,其他保存照片

MediaStore.EXTRA_OUTPUT renders data null, other way to save photos?(MediaStore.EXTRA_OUTPUT 呈現數據為空,其他保存照片的方式?)
本文介紹了MediaStore.EXTRA_OUTPUT 呈現數據為空,其他保存照片的方式?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

Google 提供了這種通過意圖拍照的通用代碼:

Google offers this versatile code for taking photos via an intent:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

    // start the image capture Intent
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

問題是,如果您像我一樣想要將照片作為附加信息傳遞,使用 EXTRA_OUTPUT 似乎會丟失照片數據,并使后續操作認為意圖數據為空.

The problem is that if you're like me and you want to pass the photos as extras, using EXTRA_OUTPUT seemingly runs off with the photo data and makes subsequent actions think the intent data is null.

看來這是Android的一個大錯誤.

It appears this is a big bug with Android.

我正在嘗試拍照,然后在新視圖中將其顯示為縮略圖.我想將它保存為用戶畫廊中的全尺寸圖像.有誰知道不使用 EXTRA_OUTPUT 來指定圖像位置的方法嗎?

I'm trying to take a photo then display it as a thumbnail in a new view. I'd like to have it saved as a full sized image in the user's gallery. Does anyone know a way to specify the image location without using EXTRA_OUTPUT?

這是我目前擁有的:

public void takePhoto(View view) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
//  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
}

/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri(int type){
      return Uri.fromFile(getOutputMediaFile(type));
}

/** Create a File for saving an image or video */
@SuppressLint("SimpleDateFormat")
private static File getOutputMediaFile(int type){

    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "JoshuaTree");

    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("JoshuaTree", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE){
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
        "IMG_"+ timeStamp + ".jpg");
    } else {
        return null;
    }

    return mediaFile;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            handleSmallCameraPhoto(data);
        }
    }
}


private void handleSmallCameraPhoto(Intent intent) {
    Bundle extras = intent.getExtras();
    mImageBitmap = (Bitmap) extras.get("data");
    Intent displayIntent = new Intent(this, DisplayPhotoActivity.class);
    displayIntent.putExtra("BitmapImage", mImageBitmap);
    startActivity(displayIntent);
}

}

推薦答案

如果你指定了MediaStore.EXTRA_OUTPUT,那么拍攝的圖像將被寫入該路徑,并且不會給onActivityResult任何數據.您可以從您指定的內容中讀取圖像.

If you specified MediaStore.EXTRA_OUTPUT, the image taken will be written to that path, and no data will given to onActivityResult. You can read the image from what you specified.

在此處查看另一個已解決的相同問題:Android 相機:數據意圖返回 null

See another solved same question here: Android Camera : data intent returns null

這篇關于MediaStore.EXTRA_OUTPUT 呈現數據為空,其他保存照片的方式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why does the android emulator camera stop unexpectedly?(為什么android模擬器相機會意外停止?)
Android camera , onPictureTaken(byte[] imgData, Camera camera) method amp; PictureCallback never called(Android camera , onPictureTaken(byte[] imgData, Camera camera) 方法 amp;PictureCallback 從未調用過) - IT屋-程序員軟件開發技
Understanding the libGDX Projection Matrix(了解 libGDX 投影矩陣)
QR code reading with camera - Android(使用相機讀取二維碼 - Android)
IP camera with OpenCv in Java(Java中帶有OpenCv的IP攝像頭)
Android mock Camera(Android 模擬相機)
主站蜘蛛池模板: 国产精品久久久久久52avav | 免费看a| 久久久久国产成人精品亚洲午夜 | 国产一级片久久久 | 久久中文高清 | 日韩一级不卡 | 97国产成人 | 奇米超碰 | 91在线观看免费 | 久久久激情视频 | 麻豆精品久久久 | 欧区一欧区二欧区三免费 | 久久亚洲欧美日韩精品专区 | 国产91av视频在线观看 | 一级黄色毛片免费 | 91精品国产综合久久久密闭 | 久久精品播放 | 黄色a三级 | 欧美精品一区二区三区在线播放 | 国产精品美女一区二区 | 午夜视频在线视频 | 欧美综合精品 | 日本免费在线 | 久久99国产精一区二区三区 | 日韩在线第一 | 精品影院| 中文字幕1区 | 国产中文原创 | 97在线观看 | 自拍偷拍亚洲欧美 | 国产一区二区三区精品久久久 | 久久视频精品 | 一级黄色录像片子 | 国产99久久久国产精品 | 久久青视频 | 日韩欧美一区二区三区四区 | 精品视频在线免费观看 | 亚洲精品成人免费 | 欧美性一级 | 欧美一区二区三区久久精品 | 国产福利免费视频 |