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

Hug*_*yez 5 android drive android-bitmap google-drive-android-api

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

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.");
                    }
Run Code Online (Sandbox Code Playgroud)

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

我已经尝试过这个解决方案将位图转换为byteArray android

但随后在驱动器中,照片无法识别为媒体文件,无法读取.我可能失败了.

编辑:我究竟做了同样的事情,是有/sf/answers/910054211/,做这种办法让我的位图ActivityResult:

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

MIk*_*mik 1

对于获取实际图像,使用捕获图像的预定义路径

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
this.startActivityForResult(cameraIntent, 101);  
Run Code Online (Sandbox Code Playgroud)

捕获图像后,您可以在cameraIntent中设置的路径上获取捕获的图像。如果您不想设置预定义路径,请检查意图数据。

    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) {}
}
Run Code Online (Sandbox Code Playgroud)

请参阅此链接使用 GD API 将大文件上传到 Google 云端硬盘进行 Google 云端硬盘上传。