在android中旋转保存的位图 [英] Rotate a saved bitmap in android

查看:37
本文介绍了在android中旋转保存的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从处于横向模式的相机中保存图像.所以它以横向模式保存,然后我在它上面应用一个覆盖层,它也是横向模式.我想旋转那个图像然后保存.例如如果我有这个

I am saving an image from the camera that was in landscape mode. so it gets saved in landscape mode and then i apply an overlay onto it that too is in landscape mode. I want to rotate that image and then save. e.g. if i have this

我想顺时针旋转 90 度一次并将其保存到 SD 卡:

I want to rotate clockwise by 90 degrees once and make it this and save it to sdcard:

这是如何实现的?

推荐答案

void rotate(float x)
    {
        Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.tedd);

        int width = bitmapOrg.getWidth();

        int height = bitmapOrg.getHeight();


        int newWidth = 200;

        int newHeight  = 200;

        // calculate the scale - in this case = 0.4f

         float scaleWidth = ((float) newWidth) / width;

         float scaleHeight = ((float) newHeight) / height;

         Matrix matrix = new Matrix();

         matrix.postScale(scaleWidth, scaleHeight);
         matrix.postRotate(x);

         Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,width, height, matrix, true);

         iv.setScaleType(ScaleType.CENTER);
         iv.setImageBitmap(resizedBitmap);
    }

这篇关于在android中旋转保存的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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