Upload photos to disk without compression

I want to upload a photo from the camera directly to the disk folder:

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

So, I do it and work. The problem is that my photos on the disc are of very low quality and I need to have high quality video.

I already tried this solution Convert a bitmap to byteArray android

But then on Drive, the photo was not recognized as a multimedia file and cannot read it. Maybe I failed something.

EDIT: I did the exact same thing as https://stackoverflow.com/a/1671622/11 and did it to get the bitmap in the ActivityResult:

 try { mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData()); } catch (IOException e) { e.printStackTrace(); } 
+5
source share
2 answers

To get a predefined path to get the actual image of the captured image using

 Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); this.startActivityForResult(cameraIntent, 101); 

After the captured image, you can get the captured image along the path set in CameraIntent. If you do not want to set a predefined path, check the Intent data.

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

Send the Download large files link to Google Drive using the GD API to download Google Drive.

+1
source

I did not ask for the rights to WRITE_EXTERNAL_STORAGE, it was in my manifest, but with api23 I need to explicitly specify and ask if the user is normal.

Now thatโ€™s good.

+1
source

Source: https://habr.com/ru/post/1257953/


All Articles