Guest User

Untitled

a guest
Dec 11th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. @Override
  2. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  3. super.onActivityResult(requestCode, resultCode, data);
  4.  
  5. if (resultCode == RESULT_OK) {
  6. if (requestCode == REQUEST_TAKE_PHOTO || requestCode == REQUEST_PICK_PHOTO) {
  7. if (data != null) {
  8. // Get the Image from data
  9. Uri selectedImage = data.getData();
  10.  
  11. String[] filePathColumn = {MediaStore.Images.Media.DATA};
  12.  
  13. Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
  14. assert cursor != null;
  15. cursor.moveToFirst();
  16.  
  17.  
  18. int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  19. mediaPath = cursor.getString(columnIndex);
  20.  
  21. // REDUZIR O TAMANHO DO ARQUIVO
  22.  
  23. Bitmap bmp = BitmapFactory.decodeFile(mediaPath);
  24. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  25. bmp.compress(Bitmap.CompressFormat.JPEG, 50, bos);
  26.  
  27.  
  28. if(imageView == null) {
  29. imageView.setImageBitmap(BitmapFactory.decodeFile(mediaPath));
  30. }
  31. else if(imageView != null){
  32. imageView2.setImageBitmap(BitmapFactory.decodeFile(mediaPath));
  33. } else if(imageView2 != null) {
  34. imageView3.setImageBitmap(BitmapFactory.decodeFile(mediaPath));
  35. }
  36. cursor.close();
  37.  
  38. postPath = mediaPath;
  39. }
  40.  
  41.  
  42. }else if (requestCode == CAMERA_PIC_REQUEST){
  43. if (Build.VERSION.SDK_INT > 21) {
  44.  
  45. Glide.with(this).load(mImageFileLocation).into(imageView);
  46. postPath = mImageFileLocation;
  47.  
  48. }else{
  49. Glide.with(this).load(fileUri).into(imageView);
  50. postPath = fileUri.getPath();
  51. }
  52. }
  53. }
  54. else if (resultCode != RESULT_CANCELED) {
  55. Toast.makeText(this, "Ocorreu um erro!", Toast.LENGTH_LONG).show();
  56. }
  57. }
Add Comment
Please, Sign In to add comment