如何根据屏幕尺寸裁剪图像?

时间:2015-08-15 19:56:14

标签: android size wallpaper

我最近问了一个问题,我想,我理解了我的问题(Why I get defected image from ImageCropper( android wallpaper app)?)。当我裁剪区域时,它需要该区域的大小(足够小),当我将其设置为壁纸时,它会增加尺寸并且我的质量会变差。所以,我确信我必须在这里改变一些事情:

public void performCrop(Uri picUri, int width, int height){
    try {
        utils = new Utils(getApplicationContext());
        int height1, width1;
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        height1 = size.y;
        width1 = size.x;


        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", width1*5);
        cropIntent.putExtra("aspectY", height1*5);
        //indicate  X and Y
        cropIntent.putExtra("outputX", width);
        cropIntent.putExtra("outputY", height);
        //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();
    }
}

任何人都可以帮助我吗?如果可能,请显示代码。

0 个答案:

没有答案