如何裁剪和机器人编程旋转图像?机器人、图像

2023-09-04 07:27:08 作者:Mickey 米奇

我想通过90度旋转的图像,也想裁剪从手机图库中取出的形象。我怎样才能做到这一点的操作以编程方式在android的?

I want to rotate the image by 90 degree and also want to crop the image taken out from gallery of phone. How can I do this operation programmatically in android?

推荐答案

要执行,你可以有以下code图像旋转:

To perform the rotation of the image you can have the following code:

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);

和从画廊的拍摄图像裁剪使用code以下片段:

and for image cropping taken from gallery use the following snippet of code :

    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);

希望,这将是对你有所帮助。

Hope, this will be helpful for you.

 
精彩推荐