2

Your application will then display an image on the screen.

A small resizable rectangular box is also displayed on the screen which the user can drag using touch. This would allow user to select any rectangular portion of the image.

How do I accomplish this. I have no idea how to proceed. How do make a rectangular box, drag it using touch and then select the that portion of image?

4

2 回答 2

1

Try the below code , it works me perfect. Any doubts let me know

Intent intent = new Intent("com.android.camera.action.CROP");
                // this will open all images in the Galery
                intent.setDataAndType(uriOfYOurImageThatToBeEdited, "image/*");
                intent.putExtra("crop", "true");
                // this defines the aspect ration
                intent.putExtra("aspectX", widthOfImage);
                intent.putExtra("aspectY", heightOfImage);
                // this defines the output bitmap size
                intent.putExtra("outputX", widthOfImage);
                intent.putExtra("outputY", heightOfImage);
                // true to return a Bitmap, false to directly save the cropped iamge
                intent.putExtra("return-data", false);
                //save output image in uri
                intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedImageUri);
                System.out.println("CroppedImageUri : "+ croppedImageUri);
                startActivityForResult(intent, 200);
于 2013-03-30T07:24:13.000 回答
1

You can use canvas to draw a rectangular box of any size on the image. Then you can use touch listeners' ACTION_DOWN event to detect if user has touched within the rectangular area. And use ACTION_MOVE event to drag rectangle area over the image.

This link http://android-developers.blogspot.in/2010/06/making-sense-of-multitouch.html should give you a start with touch events.

于 2013-03-30T07:27:49.390 回答