使用矩阵旋转位图
使用矩阵旋转位图时,顶点不稳定。
矩阵矩阵 = new Matrix(); 矩阵.postRotate(mDegree,100,100); mCompasstemp = Bitmap.createBitmap(mCompPic, 0, 0, mCompPic.getWidth(), mCompPic.getHeight(), 矩阵, true); mCompassHud.setImageBitmap(mCompasstemp);
我的代码的输出就像 -位图将旋转。 - 我的位图的顶点不稳定。 -位图正在调整大小
我需要禁用图像调整大小并使旋转稳定。您能否为此建议一个解决方案?
While rotating a bitmap using matrix, vertex is not stable..
Matrix matrix = new Matrix(); matrix.postRotate(mDegree,100,100); mCompasstemp = Bitmap.createBitmap(mCompPic, 0, 0, mCompPic.getWidth(), mCompPic.getHeight(), matrix, true); mCompassHud.setImageBitmap(mCompasstemp);
Output of my code is like
-bitmap will rotate.
-vertex of my bitmap is not stable.
-Bitmap is resizing
I need disable image resizing and make the rotation stable.Can you please suggest a solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不是直接从原始位图创建新位图,另一个(更直接,恕我直言)选项是创建生成的位图,使用该位图创建画布,然后在画布上进行旋转/平移/缩放并绘制原始位图位图通过画布到新位图上。
基本上,您正在寻找:
Rather than creating your new Bitmap directly from the original, another (more straight-forward, imho) option is to create the resultant Bitmap, create a Canvas with that Bitmap, then do your rotation/translation/scaling on the Canvas and draw the original Bitmap onto the new Bitmap via the Canvas.
Basically, you're looking, then, at:
不确定这是否是您想要的,但它可能会有所帮助。
Android 使用其内置的兼容性功能来针对不同像素密度的屏幕适当地缩放和渲染位图。缩放的方法有两种,预缩放和自动缩放。
它将从资源中预先缩放位图,并在内部绘制位图时自动缩放(这就是您使用 createBitmap 所做的事情)。
转到 http://developer.android.com/guide/practices/screens_support.html 并检查:
4.使用密度和/或尺寸特定的资源:
位图和九个补丁的预缩放和自动缩放
Not sure if this is what your looking for but it might help.
Android uses its built in compatibility features to scale and render a bitmap appropriately for screens with different pixel densities. There are two methods of scaling, pre-scaling and auto-scaling.
It will pre-scale bitmaps' from resources and auto-scales when the bitmap is being drawn internally (which is what your doing be using createBitmap).
Go to http://developer.android.com/guide/practices/screens_support.html and check under:
4.Use density and/or size-specific resources:
Pre-scaling and auto-scaling of bitmaps and nine-patches
我已经尝试过这段代码,并且旋转在位图中心稳定
,然后在画布中 doDraw()
Xpos 和 Ypos 是位图的 X 和 Y 位置
setMatrix(null),将矩阵设置为null,这样旋转就不会影响后面的位图
而且它并不总是创建新的位图,因此对于性能来说非常有用
我希望有帮助
I have tried this code, and the rotate is stable at the center of the bitmap
and then in canvas doDraw()
The Xpos and Ypos is the X and Y position of the bitmap
The setMatrix(null), set the matrix to null, so that the rotate didn't affect the after bitmap
And it didn't always create new bitmap, so it's great for performance
I hope that help
我知道这是一个老问题,但是,所有带有代码的答案都意味着画布,所以这里有一个适合我的没有画布的解决方案:
所以基本上在旋转位图后,您将其重新缩放到所需的大小。可能不是最佳实践,但至少如果您不想/不需要的话,您不必创建额外的画布,因为涉及 Paint() 对象也不是一个便宜的操作。
I know its an old question but, all answers with code imply a canvas, so heres a solution without a canvas that worked for me :
So basically after rotating your bitmap you rescale it to the desired size. Might not be best practice, but at least you dont have to create an extra canvas if you dont want/need to, since the involving Paint() Object is not an inexpensive operation either.