久久久久久久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ù)為空,其他保存照片的方式?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

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 似乎會丟失照片數(shù)據(jù),并使后續(xù)操作認為意圖數(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.

看來這是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任何數(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.

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

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

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

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

相關(guān)文檔推薦

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 從未調(diào)用過) - IT屋-程序員軟件開發(fā)技
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 模擬相機)
主站蜘蛛池模板: 另类亚洲视频 | 欧美日韩在线成人 | 一级做a爰片性色毛片16 | 福利一区二区 | 九色91视频| 亚洲视频在线播放 | 欧美精品在线免费观看 | 一区二区欧美在线 | 久久久久久网站 | 国产不卡一区 | 免费在线观看毛片 | 日本三级电影在线看 | 国产黄色在线观看 | 夜夜久久 | 欧美区日韩区 | 成人精品一区二区户外勾搭野战 | 欧美日韩一区二区三区在线观看 | 国产精品久久久久无码av | 无码日韩精品一区二区免费 | 久久综合一区二区三区 | 国产精品视频一区二区三区 | 香蕉大人久久国产成人av | 国产日韩欧美在线观看 | 国产精品视频一区二区三区四区国 | 91极品尤物在线播放国产 | 九色91视频 | 日日夜夜天天久久 | 久久久久久久久久久久久久国产 | 亚洲精品国产电影 | 日韩成人免费视频 | 成人不卡 | 99tv| 五月天婷婷激情 | 国产精品久久99 | 欧美精品1区 | 中文字幕不卡视频在线观看 | 久久www免费视频 | 91精品久久久久久久久久入口 | 日本欧美国产在线观看 | 天天视频一区二区三区 | 欧美久久一级特黄毛片 |