Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onImageGalleryClicked(View v) {
- Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
- File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
- String pictureDirectoryPath = pictureDirectory.getPath();
- Uri data = Uri.parse(pictureDirectoryPath);
- photoPickerIntent.setDataAndType(data, "image/*");
- startActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK) {
- //if we are here, everything has been processed successfully
- if (requestCode == IMAGE_GALLERY_REQUEST) {
- Uri imageUri = data.getData();
- InputStream inputStream;
- try {
- inputStream = getContentResolver().openInputStream(imageUri);
- Bitmap image = BitmapFactory.decodeStream(inputStream);
- int w = image.getWidth();
- int h = image.getHeight();
- pixels = new int[4*w*h];
- int a = 20; //this is the width of the smaller image that we are cropping to sum up
- int b = 20; ////this is the length(height) of the smaller image that we are cropping to sum up
- int tempmax = 0;
- int sum = 0;
- int k = 0;
- for (int i =0; i< h - b; i++) {
- for (int j = 0; j < w-a; j++) {
- image.getPixels(pixels, k*i+j,0, j, i, a, b);
- for (int e = 0; e < a*b; e++) {
- sum = sum + pixels[e+k*i+j];
- }
- if (sum > tempmax) {
- tempmax = sum;
- }
- sum = 0;
- }
- k = k + 1;
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- Toast.makeText(this, "Unable to open image", Toast.LENGTH_LONG).show();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment