旋转图像来自uri

时间:2014-09-25 14:40:49

标签: android matrix

我有一个从uri接收图像的imageviewer应用程序组件。我怎么旋转它?矩阵似乎不起作用。这是我的代码

public class ImageViewer扩展了Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceStatey);
    setContentView(R.layout.image_view_layout);
    Uri uri = getIntent() != null ? getIntent().getData() : null;
    ImageView img = (ImageView) findViewById(R.id.imageView);
    img.setImageURI(uri);
    Matrix matrix=new Matrix();
    matrix.postRotate(90);
    img.setImageMatrix(matrix);

1 个答案:

答案 0 :(得分:0)

一些android旋转代码。将您的URI提供给解码器......

                            Bitmap lbit =   
                            BitmapFactory.decodeStream(
                                    getContentResolver().openInputStream(_uri),null,options);

                            Log.i(TAG, "Rotating... " + rotation);
                            lbit = lbit.copy(Bitmap.Config.ARGB_8888, true);
                            Matrix matrix = new Matrix();
                            matrix.postRotate(rotation);
                            lbit = Bitmap.createBitmap(lbit, 0, 0, lbit.getWidth(),
                                    lbit.getHeight(), matrix, true);