Savage F. Morgan

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
private void performCrop() {
    try {
        //call the standard crop action intent (the user device may not support it)
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri
        cropIntent.setDataAndType(mImageCaptureUri, "image/*");
        //set crop properties
        cropIntent.putExtra("crop", "true");
        //indicate aspect of desired crop
        cropIntent.putExtra("aspectX", 4);
        cropIntent.putExtra("aspectY", 3);
        //indicate output X and Y
        cropIntent.putExtra("outputX", 800);
        cropIntent.putExtra("outputY", 800);

    File f = new File(Environment.getExternalStorageDirectory(),
            "/temporary_holder.jpg");
        try {
            f.createNewFile();
        } catch (IOException ex) {
        Log.e("io", ex.getMessage());  
        }

uri = Uri.fromFile(f);

      cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        startActivityForResult(cropIntent, PIC_CROP);

    } //respond to users whose devices do not support the crop action
    catch (ActivityNotFoundException anfe) {
        //display an error message
        String errorMessage = "Your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}

onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

         if (requestCode == PIC_CROP) {

                  String filePath = Environment.getExternalStorageDirectory()
                        + "/temporary_holder.jpg";

                thumbnail = BitmapFactory.decodeFile(filePath);



                       //thumbnail =    BitmapFactory.decodeFile(filePath);
               //    Log.i("",String.valueOf(thumbnail.getHeight()));

                    ImageView image = (ImageView) findViewById(R.id.pestImage);
                    image.setImageBitmap(thumbnail);
                    }}

http://stackoverflow.com/questions/15807766/android-crop-image-size

http://stackoverflow.com/questions/17812039/android-image-crop

http://stackoverflow.com/questions/16182120/custom-android-image-crop/16733460#16733460

http://stackoverflow.com/questions/15228812/crop-image-android-android

posted on 2014-04-23 11:39  罗斯摩根  阅读(1327)  评论(0编辑  收藏  举报