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

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

问题描述

我现在的储蓄从相机那是在横向模式下的图像。所以它被保存在横向模式下,然后我申请一个覆盖到它那也是在横向模式。我要旋转的图像,然后保存。例如如果我有这样的

我想通过90度的一次顺时针旋转,使之本,并将其保存到SD卡:

这是怎么实现?

解决方案

 无效旋转(浮动X)
    {
        位图bitmapOrg = BitmapFactory.de codeResource(getResources(),R.drawable.tedd);

        INT宽度= bitmapOrg.getWidth();

        INT高= bitmapOrg.getHeight();


        INT newWidth = 200;

        INT newHeight = 200;

        //计算比例 - 在这种情况下= 0.4f

         浮动scaleWidth =((浮点)newWidth)/宽度;

         浮动scaleHeight =((浮点)newHeight)/身高;

         字模=新的Matrix();

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

         位图resizedBitmap = Bitmap.createBitmap(bitmapOrg,0,0,宽度,高度,矩阵,真);

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

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

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

How is this to be accomplished?

解决方案

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天全站免登陆