最快的旋转大尺寸位图的方式 [英] Fastest way to rotate big size bitmap

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

问题描述

我正与大尺寸的图像,当我将其旋转(位图上的应用矩阵)很多秒发生。 我已经看到了Android系统的画廊可以以非常快速的方式,而不是完成此任务。这怎么可能?

我想执行上的AsyncTask旋转,只适用ImageView的旋转(这并不需要很长时间)在主线程,但如果应用程序是AsyncTask的杀害前到达终点,应用程序下跌不一致的状态。

这是我的位图的旋转code,这需要很长的时间执行的大位图:

 矩阵垫=新的Matrix();
mat.setRotate(90);
BMAP = Bitmap.createBitmap(BMAP,0,0,bMap.getWidth(),bMap.getHeight(),垫,真正的);
 

解决方案

在做修改,一个大的图像,创建它的低品质的位图副本,并用它来显示即时旋转或其他编辑效果。一旦用户停止运动(或左滑块控制)取代低品质的位图与应用了相同的效果的原始图像。这将显著改善用户体验。尝试,让我知道。

这听起来像是从原来的偏差规定─可以得出旋转整个图像进行实时的矩形来代替。最后,需要什么用户是多少他的图像已经旋转的指示。这将是更快,可以很容易地无滞后UI线程上完成的。

这是在画布上code最简单的旋转

  canvas.save(); //保存画布的位置
canvas.rotate(角,X +(imageW / 2)中,Y +(imageH / 2)); //旋转画布
canvas.drawBitmap(imageBmp,X,Y,NULL); //绘制图像旋转画布上
canvas.restore(); //恢复画布的位置。
 

I am working with large size images and when I try to rotate them (applying matrix on the bitmap) a lot of seconds occurs. I've seen that android system gallery can accomplish this task in a very fast manner instead. How is it possible?

I thought to perform the rotation on an asyncTask, applying only the ImageView rotation (which doesn't take long time) on the main thread, but if the app is killed before the asyncTask get to the end, the app fall in an inconsistent state.

This is my bitmap rotation code, which takes long time execution for large bitmaps:

Matrix mat = new Matrix();
mat.setRotate(90);
bMap = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), mat, true);

解决方案

When doing modifications to a large image, create a low quality bitmap copy of it and use it for showing instant rotation or other editing effects. Once user is stopped motion (or left slider control) replace the low quality bitmap with the original image with same effects applied to it. This will significantly improve user experience. Try and let me know.

This might sound like a deviation from the original requirement- you can draw a rectangle instead of rotating the whole image in real time. In the end, what user needs is an indication of how much his image has rotated. This will be faster and can easily be done on UI thread without lag.

This is the simplest rotation on canvas code

canvas.save(); //save the position of the canvas
canvas.rotate(angle, X + (imageW / 2), Y + (imageH / 2)); //rotate the canvas
canvas.drawBitmap(imageBmp, X, Y, null); //draw the image on the rotated canvas
canvas.restore();  // restore the canvas position.

这篇关于最快的旋转大尺寸位图的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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