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

MediaStore.EXTRA_OUTPUT 呈現(xiàn)數(shù)據(jù)為空,其他保存照片

MediaStore.EXTRA_OUTPUT renders data null, other way to save photos?(MediaStore.EXTRA_OUTPUT 呈現(xiàn)數(shù)據(jù)為空,其他保存照片的方式?)
本文介紹了MediaStore.EXTRA_OUTPUT 呈現(xiàn)數(shù)據(jù)為空,其他保存照片的方式?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

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

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

問(wèn)題是,如果您像我一樣想要將照片作為附加信息傳遞,使用 EXTRA_OUTPUT 似乎會(huì)丟失照片數(shù)據(jù),并使后續(xù)操作認(rèn)為意圖數(shù)據(jù)為空.

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.

看來(lái)這是Android的一個(gè)大錯(cuò)誤.

It appears this is a big bug with Android.

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

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,那么拍攝的圖像將被寫入該路徑,并且不會(huì)給onActivityResult任何數(shù)據(jù).您可以從您指定的內(nèi)容中讀取圖像.

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.

在此處查看另一個(gè)已解決的相同問(wèn)題:Android 相機(jī):數(shù)據(jù)意圖返回 null

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

這篇關(guān)于MediaStore.EXTRA_OUTPUT 呈現(xiàn)數(shù)據(jù)為空,其他保存照片的方式?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Why does the android emulator camera stop unexpectedly?(為什么android模擬器相機(jī)會(huì)意外停止?)
Android camera , onPictureTaken(byte[] imgData, Camera camera) method amp; PictureCallback never called(Android camera , onPictureTaken(byte[] imgData, Camera camera) 方法 amp;PictureCallback 從未調(diào)用過(guò)) - IT屋-程序員軟件開發(fā)技
Understanding the libGDX Projection Matrix(了解 libGDX 投影矩陣)
QR code reading with camera - Android(使用相機(jī)讀取二維碼 - Android)
IP camera with OpenCv in Java(Java中帶有OpenCv的IP攝像頭)
Android mock Camera(Android 模擬相機(jī))
主站蜘蛛池模板: 久久久久网站 | 亚洲精品视频在线播放 | 国产成人精品久久久 | 日韩精品在线播放 | 国产一区二区三区精品久久久 | 国产精品视频一区二区三区四蜜臂 | 在线观看国产91 | 成人啊啊啊| 美女天天干天天操 | 色欧美片视频在线观看 | 国产精品a一区二区三区网址 | 欧美福利| 久久久女女女女999久久 | 国产精品国产三级国产aⅴ原创 | 一区二区三区精品视频 | 日韩成人在线视频 | 国产剧情久久 | 国产区视频在线观看 | 国产91综合一区在线观看 | 日韩国产在线 | 黄色大全免费看 | 99视频在线 | 一区在线视频 | 亚洲久久久 | 欧美福利视频一区 | 中文字幕一区二区三区日韩精品 | 国产精品国产三级国产aⅴ无密码 | 国产欧美精品区一区二区三区 | 欧美成人第一页 | 国产伦精品一区二区三区高清 | 国产精品视频一区二区三区不卡 | 日韩午夜影院 | 台湾a级理论片在线观看 | 性国产丰满麻豆videosex | 亚洲乱码一区二区三区在线观看 | 天天看天天操 | www.日本国产 | japan21xxxxhd美女 日本欧美国产在线 | 久久精品91| 亚洲视频免费在线观看 | 亚洲精品福利在线 |