如何裁剪和机器人编程旋转图像? [英] How to crop and rotate image programmatically in android?

查看:118
本文介绍了如何裁剪和机器人编程旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过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.

这篇关于如何裁剪和机器人编程旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆