Question

I´m learning android/java by myself @the moment and i have a problem with a part of my app i´m learning on.

I made the code with help of the www and my problem is that if i open an image from the gallery it´s send to the edit activity but the quality of the picture is really bad.

Code with the main problem i think:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case PICK_IMAGE_FROM_GALLERY:
            {
                if (resultCode == RESULT_OK)
                {
                        Log.d(TAG, "Got Picture!");
                        Log.d(TAG,"File type - " + data.getType());
                        Uri photoUri = data.getData();
                        if (photoUri != null)
                        {
                            try {
                                String[] filePathColumn = {MediaStore.Images.Media.DATA};
                                String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
                                int orientation = -1;
                                Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null); 
                                cursor.moveToFirst();
                                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                                String filePath = cursor.getString(columnIndex);
                                cursor.close();
                                cursor = getContentResolver().query(photoUri, orientationColumn, null, null, null);
                                if(cursor != null && cursor.moveToFirst()){
                                    orientation = cursor.getInt(cursor.getColumnIndex(orientationColumn[0]));
                                }
                                cursor.close();

                                HashMap<String, Integer> pRes = this.getImageResolutionSetting();
                                Bitmap shrunkenBitmap = FileUtilsHelper.shrinkBitmap(filePath, pRes.get("width"), pRes.get("height"));
                                shrunkenBitmap = rotateBitmapToOrientation(shrunkenBitmap, orientation);
                                String res = FileUtilsHelper.saveBitmapAsJpeg(shrunkenBitmap, this);
                                Log.d(TAG,"File Path: " + res);
                                shrunkenBitmap.recycle();
                                Intent editImage = new Intent(this, EditImage.class);
                                editImage.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
                                editImage.putExtra("stuff.path", res);

                                startActivity(editImage);
                            }catch(Exception e){
                                Toast.makeText(this, R.string.cant_save_image,Toast.LENGTH_SHORT).show();

                            }

                        }

                }
            }
            break;
            }
}}

I want now to rewrite the complete onActivityResult so it´s using 1:1 the picture from the gallery or remove the parts: shrinkBitmap (i think thats the main problem of the bad quality) rotateBitmapToOrientation (because it´s always false orientated)

But i don´t know how that is working...

If i´m deleting that parts it´s not working anymore i could really need a teacher on that :)

Thx for your help dudes!!

Was it helpful?

Solution

In filePath you have the file path. So if you pass it (via putExtra()) instead of res, you will edit the original image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top