我必须以角度旋转图像并通过android裁剪意图裁剪。当我单击旋转按钮时,图像应以一定角度旋转并显示在图像视图中,当我单击裁剪按钮时,旋转的图像应发送到android crop intent。
这样,每当我点击旋转按钮时,角度可能会发生变化,图像视图中显示的相应旋转图像应该通过android裁剪动作进行裁剪。
我尝试了所有角度的旋转图像,它工作正常。但每当我单击裁剪按钮时,旋转的图像不会传递到裁剪而是原始图像正在传递。
这是我的代码
image.setImageURI(imageURI);
if (savedInstanceState != null) {
rotation = savedInstanceState.getInt("ANGLE");
}
mTempUri = HomeActivity.getOutputMediaFileUri("XXX",
"test1", MEDIA_TYPE_IMAGE, true);
{
crop.setOnClickListener (新的OnClickListener(){
@Override
public void onClick(View v) {
doCrop();
}
});
rotate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"Rotating.. Please wait", Toast.LENGTH_SHORT).show();
rotate_Image();
}
});
}
public void doCrop() {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(
intent, 0);
int size = list.size();
if (size == 0) {
Toast.makeText(this, "Can not find image crop app",
Toast.LENGTH_SHORT).show();
return;
} else {
intent.setData(imageURI);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mTempUri);
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent(new ComponentName(res.activityInfo.packageName,
res.activityInfo.name));
startActivityForResult(i, CROP_FROM_CAMERA);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case CROP_FROM_CAMERA:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
this.finish();
break;
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("ANGLE", rotation);
super.onSaveInstanceState(outState);
}
public void rotate_Image() {
rotation += 90;
rotation %= 360;
bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),
imageURI);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bitmap1 = getRotatedBitmap(bitmap);
image.setImageBitmap(bitmap1);
}
private Bitmap getRotatedBitmap(Bitmap bitmap) {
if (rotation % 360 == 0) {
return bitmap;
}
Matrix matrix = new Matrix();
matrix.postRotate(rotation, bitmap.getWidth() / 2,
bitmap.getHeight() / 2);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
}
}
答案 0 :(得分:1)
https://github.com/KyoSherlock/CropView
以下是使用平移,缩放和旋转裁剪图像的自定义视图。(但不是意图) 裁剪矩形是固定的,图像可以通过手势翻译。
答案 1 :(得分:0)
我使用了https://github.com/edmodo/cropper,
我发现它很方便,因为所有动作都发生在一个ImageView
中,你甚至可以在裁剪矩形中移动/放置或移除网格。