我想将相机中的照片直接上传到驱动器文件夹中:
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
但随后在云端硬盘中,照片未被识别为媒体文件且无法读取。我可能做错了什么。
编辑:我做了完全一样的事情,那里是https://stackoverflow.com/a/13000774/6644403并通过这种方式在 ActivityResult 中获取我的位图:
try {
mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
最佳答案
对于获取实际图像预定义路径的捕获图像使用
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) {}
}
引用此链接 Upload large files to Google Drive using GD API用于谷歌驱动器上传。
关于android - 将照片上传到驱动器而不压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39953898/