我有一个带触摸监听器的图像视图,我能够将所有触摸输入捕获到矩阵中,并将该矩阵应用于图像平移和适当缩放的图像视图。
我的问题:我现在想以这样的方式对图像进行裁剪,使其始终与我在图库中选择的图像大小相同。
换句话说,假设我的屏幕中间有一个512x512的正方形,用户平移并缩放图像,直到感兴趣的项目适合该正方形,然后单击“完成”#34;。我希望得到的图像裁剪出包含在图像视图中的照片。
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.customizeimage);
// imagview = (ImageView) findViewById(R.id.imageView1);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// To open up a gallery browser
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"), 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
//this is where the image pan and zoom
final ImageView imageView = (ImageView) findViewById(R.id.imageGet);
imageView.setOnTouchListener(new OnTouch());
// currImageURI is the global variable I'm using to hold the
// content:// URI of the image
currImageURI = data.getData();
// String selectedImagePath=getRealPathFromURI(currImageURI);
imageView.setImageURI(currImageURI);
Log.e("" + getRealPathFromURI(GalleryImage.this, currImageURI),
"" + getImagePath(currImageURI));
}
}
}