将照片上传到驱动器而不压缩

Upload photo to drive without compression

我想将相机中的照片直接上传到驱动器文件夹中:

OutputStream outputStream = result.getDriveContents().getOutputStream();
                    ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
/* image is my Bitmap */
                    image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);

                    try {
                        outputStream.write(bitmapStream.toByteArray());
                    } catch (IOException e1) {
                        Log.i(TAG, "Unable to write file contents.");
                    }

所以我正在这样做并且它正在工作。问题是我在驱动器中的图片质量很差,我需要一个高质量的视频。

我已经尝试过这个解决方案Converting bitmap to byteArray android

但随后在云端硬盘中,照片未被识别为媒体文件且无法读取。我可能做错了什么。

编辑:我做了完全相同的事情 并通过这种方式在 ActivityResult 中获取我的位图:

try {
                    mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }

我不是在请求 WRITE_EXTERNAL_STORAGE 的权利,它在我的清单中,但由于 api 23 我需要明确并询问用户是否可以。

现在好了。

使用

获取实际图像的捕获图像的预定义路径
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
this.startActivityForResult(cameraIntent, 101);  

Captured Image 之后,您可以在 cameraIntent 中设置的路径上获取 Captured Image。如果您不想设置预定义路径,请检查 Intent 数据。

    if (resultCode == android.app.Activity.RESULT_OK && requestCode == 101) {
        try {        
            path_mm = "Onsuccess_resultcode";
            generateNoteOnSD("photo34.txt", path_mm);
            Bitmap photo = null;
            if (data == null) {
                        //get Bitmap  here.
            } else {
               Uri u1 = data.getData();
               //get uri and find actual path on that uri.
               }
           }catch(Exception ex) {}
}

参考此 link google 驱动器上传。