Q
Q
qqmthfck2015-08-15 18:59:09
Android
qqmthfck, 2015-08-15 18:59:09

Why do I send only very high-quality photos to the cropping program, and when cropping (max) I get very low-quality ones?

// layout click listeners
        llSetWallpaper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                utils = new Utils(getApplicationContext());
                bitmap = ((BitmapDrawable) fullImageView.getDrawable())
                        .getBitmap();
                File f = new File(utils.saveImageToSDCard(bitmap));
             quri = Uri.fromFile( f);
                 h = bitmap.getHeight();
                w = bitmap.getWidth();
                performCrop(quri, h, w);


            }
        });
. This is the click handler for the button that performs the performcrop();
public void performCrop(Uri picUri, int height, int width){
        try {
            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            //indicate image type and Uri
            cropIntent.setDataAndType(picUri, "image/*");
            //set crop properties
            cropIntent.putExtra("crop", "true");

            //indicate aspect of desired crop
            cropIntent.putExtra("aspectX", height);
            cropIntent.putExtra("aspectY", width);
            //indicate  X and Y
            cropIntent.putExtra("outputX", height);
            cropIntent.putExtra("outputY", width);
            //retrieve data on return
            cropIntent.putExtra("return-data", true);
            //start the activity - we handle returning in onActivityResult
            startActivityForResult(cropIntent, 1);
        }
        catch(ActivityNotFoundException anfe){
            //display an error message
            String errorMessage = "Whoops - your device doesn't support the crop action!";
            Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
            toast.show();
        }
    }
This is the code for the performCorp() method;
@Override
    protected void onActivityResult(int requestCode,int resultCode, Intent data){

    super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == 1) {

//get the cropped bitmap
            if (data != null) {
                Bundle extras = data.getExtras();
                utils = new Utils(getApplicationContext());
                Bitmap thePic = extras.getParcelable("data");
                utils.setAsWallpaper(thePic);
            }
        }
        }
Code for OnActivityResult();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Horoko, 2015-08-27
@Horoko

As far as I know, it's because of the bitmap. He somehow compresses the photo. Try using the inSampleSize = 0 method;

BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 0;
            Bitmap myBitmap = BitmapFactory.decodeFile(picture.getAbsolutePath(), options);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question