Guest User

Untitled

a guest
Feb 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. public void onImageGalleryClicked(View v) {
  2.  
  3. Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
  4. File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  5. String pictureDirectoryPath = pictureDirectory.getPath();
  6. Uri data = Uri.parse(pictureDirectoryPath);
  7. photoPickerIntent.setDataAndType(data, "image/*");
  8. startActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST);
  9.  
  10. }
  11.  
  12. @Override
  13. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  14. if (resultCode == RESULT_OK) {
  15. //if we are here, everything has been processed successfully
  16. if (requestCode == IMAGE_GALLERY_REQUEST) {
  17. Uri imageUri = data.getData();
  18. InputStream inputStream;
  19.  
  20. try {
  21. inputStream = getContentResolver().openInputStream(imageUri);
  22. Bitmap image = BitmapFactory.decodeStream(inputStream);
  23. int w = image.getWidth();
  24. int h = image.getHeight();
  25. pixels = new int[4*w*h];
  26. int a = 20; //this is the width of the smaller image that we are cropping to sum up
  27. int b = 20; ////this is the length(height) of the smaller image that we are cropping to sum up
  28. int tempmax = 0;
  29. int sum = 0;
  30. int k = 0;
  31. for (int i =0; i< h - b; i++) {
  32. for (int j = 0; j < w-a; j++) {
  33. image.getPixels(pixels, k*i+j,0, j, i, a, b);
  34. for (int e = 0; e < a*b; e++) {
  35. sum = sum + pixels[e+k*i+j];
  36. }
  37.  
  38. if (sum > tempmax) {
  39. tempmax = sum;
  40.  
  41. }
  42. sum = 0;
  43. }
  44. k = k + 1;
  45. }
  46. } catch (FileNotFoundException e) {
  47. e.printStackTrace();
  48. Toast.makeText(this, "Unable to open image", Toast.LENGTH_LONG).show();
  49.  
  50. }
  51.  
  52. }
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment