我想将图片旋转 90 度,还想裁剪从手机图库中取出的图片。我如何在 Android 中以编程方式执行此操作?
最佳答案
要执行图像的旋转,您可以使用以下代码:
Bitmap bMap = BitmapFactory.decodeResource(getResources(),R.drawable.test);
Matrix mat = new Matrix();
mat.postRotate(90);
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
bMap.getWidth(), bMap.getHeight(), mat, true);
BitmapDrawable bmd = new BitmapDrawable(bMapRotate);
image.setImageBitmap(bMapRotate);
image.setImageDrawable(bmd);
对于从图库中截取的图像,请使用以下代码 fragment :
Intent viewMediaIntent = new Intent();
viewMediaIntent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/image/*");
viewMediaIntent.setDataAndType(Uri.fromFile(file), "image/*");
viewMediaIntent.putExtra("crop","true");
viewMediaIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(viewMediaIntent,1);
关于android - 如何在 Android 中以编程方式裁剪和旋转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6571509/