旋转动画的android图像的位图 [英] Rotating an image bitmap with animation android

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

问题描述

在我的应用我给一个功能从文件路径编辑图像。
现在我想添加一个功能改变与动画图像方向,然后保存它。

我能够改变方向,但不知道如何动画添加到它。

下面是我的code。

  ImageView的IMG;
BMP位图;
位图rotatedBMP;
串imageFilePath =;
文件imgFile;
公共无效旋转(){
    如果(rotatedBMP == NULL){
        如果(imgFile = NULL&放大器;!&安培; imgFile.exists())
            BMP = BitmapFactory.de codeFILE(imgFile.getAbsolutePath());
    }其他
        BMP = rotatedBMP;
    //获取宽度放大器;给定图像的高度。
            INT W = bmp.getWidth();
            INT H = bmp.getHeight();
            矩阵MTX =新的Matrix();
            。MTX preRotate(90);
            rotatedBMP = Bitmap.createBitmap(BMP,0,0,W,H,MTX,真);
            / * BitmapDrawable BMD =新BitmapDrawable(rotatedBMP);
            img.setImageDrawable(BMD); * /
            img.setImageBitmap(rotatedBMP);
}


解决方案

有你的愿望,动画旋转视图,你的愿望,旋转和保存实际的位图之间的冲突。

如果您要旋转的图像来看,做到这一点的好办法,就是用动画更新步旋转在的onDraw 法画布,或者使用Android的帮手,像 RotateAnimation 。如果你想砸的例子我们评论。

这就是好办法,因为它并没有创建的每一个动画帧上了一个新的位图,这将是非常昂贵的。

不过,你有冲突,你也想旋转位图本身,而不仅仅是观点,这样才能保存。这是精细给予它不是每一个动画一步。

您因此将不得不拯救你要应用到的位图尽可能晚地用户选择的转换。然后,但动画的观点是在响应用户为宜。在保存,你会Concat的上写入文件中的所有用户的转换。或者是动画的想法放弃了。

我的执行办法是将本地存储的第二矩阵,让每个用户输入这两个更新画布变换的的那个矩阵。那么你'弄个位图,因为它是在保存按钮pssed $ P $,并将其应用到更新的转换矩阵。

快乐阐述的要求。

有消息

<一个href=\"http://stackoverflow.com/questions/8981845/androidrotate-image-in-imageview-by-an-angle\">ANDROID::Rotate在ImageView的图像由角度(中提到的问题太多创造了许多位图)

旋转在android系统视图(gauravjain0102的答案被低估了!)

In my app I am giving a functionality to edit an image from the filepath. Now I want to add a feature to change the image orientation with animation and then save it.

I am able to change the orientation but don't know how to add animation to it.

Here's my code.

ImageView img;
Bitmap bmp;
Bitmap rotatedBMP;
String imageFilePath="";
File imgFile;
public void rotate(){
    if(rotatedBMP == null){
        if(imgFile != null && imgFile.exists())
            bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    }else
        bmp = rotatedBMP;
    // Getting width & height of the given image.
            int w = bmp.getWidth();
            int h = bmp.getHeight();
            Matrix mtx = new Matrix();
            mtx.preRotate(90);
            rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
            /*BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
            img.setImageDrawable(bmd);*/
            img.setImageBitmap(rotatedBMP);
}

解决方案

There's a conflict between your desire to animate rotate a view, and your desire to rotate and save the actual bitmap.

If you want to rotate the image view, the good way to do that is to rotate the canvas in an onDraw method with an animation update step, or to use Android's helper for that like RotateAnimation. Drop us a comment if you want examples.

That's the "good way" because it doesn't create a new bitmap on every animation frame, which would be very expensive.

However, you've got a conflict that you also want to rotate the bitmap itself, rather than just the view, so as to save it. This is fine given it's not on every animation step.

You consequently will have to save the user's chosen transformations you want to apply to the bitmap as late as possible. Then animate the view however is appropriate in response to the user. On the save, you'd concat all the users transformations on writing to the file. Or give up on the idea of animating it.

My implementation idea would be to store a second matrix locally and have each user input both update the canvas transforms and that matrix. You'd then 'get hold' of the bitmap as it were when the save button is pressed and apply it to the updated transformation matrix.

Happy to elaborate as requested.

Some sources

ANDROID::Rotate image in imageview by an angle (mentions issues with creating many bitmaps too)

Rotating a view in android (gauravjain0102's answer is underrated!)

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

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