• <bdo id='VJahM'></bdo><ul id='VJahM'></ul>

      <i id='VJahM'><tr id='VJahM'><dt id='VJahM'><q id='VJahM'><span id='VJahM'><b id='VJahM'><form id='VJahM'><ins id='VJahM'></ins><ul id='VJahM'></ul><sub id='VJahM'></sub></form><legend id='VJahM'></legend><bdo id='VJahM'><pre id='VJahM'><center id='VJahM'></center></pre></bdo></b><th id='VJahM'></th></span></q></dt></tr></i><div id='VJahM'><tfoot id='VJahM'></tfoot><dl id='VJahM'><fieldset id='VJahM'></fieldset></dl></div>

      <tfoot id='VJahM'></tfoot>
      1. <legend id='VJahM'><style id='VJahM'><dir id='VJahM'><q id='VJahM'></q></dir></style></legend>

        <small id='VJahM'></small><noframes id='VJahM'>

        Android围绕中心旋转位图而不调整大小

        Android rotate bitmap around center without resizing(Android围绕中心旋转位图而不调整大小)

        <small id='CJojb'></small><noframes id='CJojb'>

      2. <i id='CJojb'><tr id='CJojb'><dt id='CJojb'><q id='CJojb'><span id='CJojb'><b id='CJojb'><form id='CJojb'><ins id='CJojb'></ins><ul id='CJojb'></ul><sub id='CJojb'></sub></form><legend id='CJojb'></legend><bdo id='CJojb'><pre id='CJojb'><center id='CJojb'></center></pre></bdo></b><th id='CJojb'></th></span></q></dt></tr></i><div id='CJojb'><tfoot id='CJojb'></tfoot><dl id='CJojb'><fieldset id='CJojb'></fieldset></dl></div>
          <tbody id='CJojb'></tbody>

          <legend id='CJojb'><style id='CJojb'><dir id='CJojb'><q id='CJojb'></q></dir></style></legend>
          • <bdo id='CJojb'></bdo><ul id='CJojb'></ul>
            <tfoot id='CJojb'></tfoot>

                  本文介绍了Android围绕中心旋转位图而不调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在努力围绕其中心绘制旋转位图并在不调整位图大小的情况下进行旋转.我正在通过游戏线程将我的所有精灵绘制到屏幕上,因此我正在寻找一种包含原始位图而不是画布的解决方案.

                  I'm struggling to draw a rotating bitmap around its center and do the rotating without resizing the bitmap. I'm drawing all my sprites to the screen via a game thread, so I'm looking for a solution that incorporates the original bitmap and not the canvas.

                  提前致谢.

                  到目前为止,这是我的代码,它围绕其中心旋转一个位图,然后调整它的大小.

                  This is my code so far, it turns a bitmap around its center, yet resizes it.

                  i = i + 2;
                              transform.postRotate(i, Assets.scoresScreen_LevelStar.getWidth()/2, Assets.scoresScreen_LevelStar.getHeight()/2);
                              Bitmap resizedBitmap = Bitmap.createBitmap(Assets.scoresScreen_LevelStar, 0, 0, Assets.scoresScreen_LevelStar.getWidth(), Assets.scoresScreen_LevelStar.getHeight(), transform, true);
                  
                              game.getGraphics().getCanvasGameScreen().drawBitmap(resizedBitmap, null, this.levelStar.getHolderPolygons().get(0), null);
                  

                  更新:

                  我注意到这并不像听起来那么容易.我的旋转代码不是问题.位图旋转,但 dst rect 也必须根据旋转角度增加/减少,否则 bimap 会显得更小,因为它被绘制到固定的 dst rect 中.所以我猜我必须开发一些方法来返回一个 dst rect.所以需要旋转位图而不出现调整大小的方法:

                  I've noticed this isn't as easy as it sounds. My rotating code is not the problem. The bitmap rotates, yet the dst rect will also have to increase/decrease depending on the angle of rotation, or else the bimap will appear smaller, since it's drawn into a fixed dst rect. So I'm guessing I'll have to develop some method that will return a dst rect. So the methods needed to rotate a bitmap without appeared resizing:

                  public static Bitmap rotateBitmap(Bitmap bitmap, int rotation) // I've got this method working
                  

                  public static Rect rotateRect(Rect currentDst, int rotation) // Don't got this
                  

                  我知道这需要一些数学(三角),有人愿意挑战吗?:P

                  I understand this will require some math (trig), anyone up for the challenge? :P

                  推荐答案

                  这对我有用!

                  我创建了一个返回矩阵的方法.该矩阵可用于以下绘制方法:

                  I created a method that returns a matrix. The matrix can be used in the following drawing method:

                  public void drawBitmap (Bitmap bitmap, Matrix matrix, Paint paint)
                  

                  给你!(参数形状可以轻松替换,如果您愿意,请发表评论):

                  Here you go! (The parameter shape can be replaced with ease, if you would like that, just leave a comment):

                  public static Matrix rotateMatrix(Bitmap bitmap, Shape shape, int rotation) {
                  
                          float scaleWidth = ((float) shape.getWidth()) / bitmap.getWidth();
                          float scaleHeight = ((float) shape.getHeight()) / bitmap.getHeight();
                  
                          Matrix rotateMatrix = new Matrix();
                          rotateMatrix.postScale(scaleWidth, scaleHeight);
                          rotateMatrix.postRotate(rotation, shape.getWidth()/2, shape.getHeight()/2);
                          rotateMatrix.postTranslate(shape.getX(), shape.getY());
                  
                  
                          return rotateMatrix;
                  
                      }
                  

                  注意:如果您想要动画旋转,则必须每帧使用新值更新旋转参数,例如.1 然后 2 然后 3 ...

                  NB: If you want an animated rotation, the rotation parameter will have to be updated with new values every frame eg. 1 then 2 then 3 ...

                  这篇关于Android围绕中心旋转位图而不调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

                  <small id='5l0oW'></small><noframes id='5l0oW'>

                        <tbody id='5l0oW'></tbody>
                        <bdo id='5l0oW'></bdo><ul id='5l0oW'></ul>
                        <legend id='5l0oW'><style id='5l0oW'><dir id='5l0oW'><q id='5l0oW'></q></dir></style></legend>
                        <i id='5l0oW'><tr id='5l0oW'><dt id='5l0oW'><q id='5l0oW'><span id='5l0oW'><b id='5l0oW'><form id='5l0oW'><ins id='5l0oW'></ins><ul id='5l0oW'></ul><sub id='5l0oW'></sub></form><legend id='5l0oW'></legend><bdo id='5l0oW'><pre id='5l0oW'><center id='5l0oW'></center></pre></bdo></b><th id='5l0oW'></th></span></q></dt></tr></i><div id='5l0oW'><tfoot id='5l0oW'></tfoot><dl id='5l0oW'><fieldset id='5l0oW'></fieldset></dl></div>

                            <tfoot id='5l0oW'></tfoot>