• <small id='MoJTR'></small><noframes id='MoJTR'>

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

        Android:围绕中心旋转图像

        时间:2023-05-18
        <i id='saeCQ'><tr id='saeCQ'><dt id='saeCQ'><q id='saeCQ'><span id='saeCQ'><b id='saeCQ'><form id='saeCQ'><ins id='saeCQ'></ins><ul id='saeCQ'></ul><sub id='saeCQ'></sub></form><legend id='saeCQ'></legend><bdo id='saeCQ'><pre id='saeCQ'><center id='saeCQ'></center></pre></bdo></b><th id='saeCQ'></th></span></q></dt></tr></i><div id='saeCQ'><tfoot id='saeCQ'></tfoot><dl id='saeCQ'><fieldset id='saeCQ'></fieldset></dl></div>
        1. <small id='saeCQ'></small><noframes id='saeCQ'>

              <legend id='saeCQ'><style id='saeCQ'><dir id='saeCQ'><q id='saeCQ'></q></dir></style></legend>
              <tfoot id='saeCQ'></tfoot>
                <tbody id='saeCQ'></tbody>

                  <bdo id='saeCQ'></bdo><ul id='saeCQ'></ul>

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

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试围绕中心旋转图像.这通常使用 RotateAnimation 工作,但我希望它更快一点.我现在将 SurfaceView 模式与单独的绘图线程一起使用.

                  I'm trying to rotate an image around the center. This works generally using RotateAnimation, but I want to have it a bit faster. I'm now using the SurfaceView pattern with a separate drawing thread.

                  这是正确绘制位图的代码(取决于外部标题")

                  This is code, which draws the bitmap correctly (depending on the outer "heading")

                  航向 = 以度为单位的角度,位图 = 位图,w = 位图的宽度,h = 位图的高度.

                  heading = angle in degrees, bitmap = the bitmap, w = width of the bitmap, h = height of the bitmap.

                      Matrix m = new Matrix();
                      m.preRotate(heading, w/2, h/2);
                      m.setTranslate(50,50);
                  
                      canvas.drawBitmap(bitmap, m, null);
                  

                  缺点:图像是一个圆形,上面的代码会产生可见的锯齿效果...

                  Drawback: The image is a circle and the code above produces visible aliasing effects...

                  下面的代码也在旋转图像,但在旋转时(比如顺时针从 0 度到 45 度),新图像的中心会向下/向右移动.我想,偏心效果是由于新图像的扩大宽度/高度?但是,如果设置了 filter=true,则此代码不会产生别名.有没有办法使用代码 #1 但有抗锯齿或使用代码 #2 但摆脱中心移动?

                  The code below is also rotating the image, but while rotating (say from 0 to 45 degrees clockwise) the center of the new image moves bottom/right. I suppose, the eccentric effect is due to the enlarged width/height of the new image ?? However, this code doesn't produce aliasing, if filter=true is set. Is there a way to use code #1 but have sort of anti-aliasing or use code #2 but getting rid of the center movement?

                      Matrix m = new Matrix();
                      m.preRotate(heading, w/2, h/2);
                      m.setTranslate(50,50);
                  
                      Bitmap rbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true);
                      canvas.drawBitmap(rbmp, 50, 50, null);
                  

                  更新:根据该线程中的讨论,代码 #2 的正确版本(抗锯齿 正确旋转)看起来像这样(省略了 50,50 的偏移量):

                  UPDATE: As result of the discussion in this thread the correct version of code #2 (anti-aliasing and correct rotation) would look like this (offset of 50,50 omitted):

                          Matrix m = new Matrix();
                  
                          m.setRotate(heading, w/2, h/2);
                          Bitmap rbpm = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true);
                          canvas.drawBitmap(rbpm, (w - rbpm.getWidth())/2, (h - rbpm.getHeight())/2, null);
                  

                  谢谢.

                  推荐答案

                  找到原始图像的中心并使用它找到新图像和中心:

                  Find the center of the original image and for the new image and center using that:

                  Matrix minMatrix = new Matrix();
                  //height and width are set earlier.
                  Bitmap minBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                  Canvas minCanvas = new Canvas(minBitmap);
                  
                  int minwidth = bitmapMin.getWidth();  
                  int minheight = bitmapMin.getHeight();
                  int centrex = minwidth/2;
                  int centrey = minheight/2;
                  
                  minMatrix.setRotate(mindegrees, centrex, centrey);
                  Bitmap newmin = Bitmap.createBitmap(minBitmap, 0, 0, (int) minwidth, (int) minheight, minMatrix, true);
                  
                  minCanvas.drawBitmap(newmin, (centrex - newmin.getWidth()/2), (centrey - newmin.getHeight()/2), null);
                  minCanvas.setBitmap(minBitmap);
                  

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

                  上一篇:根 ViewController 内的 UIViewController 不旋转 下一篇:旋转 UIBarButtonItem

                  相关文章

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

                    <bdo id='k8Xnb'></bdo><ul id='k8Xnb'></ul>
                  <tfoot id='k8Xnb'></tfoot>
                • <small id='k8Xnb'></small><noframes id='k8Xnb'>

                  <legend id='k8Xnb'><style id='k8Xnb'><dir id='k8Xnb'><q id='k8Xnb'></q></dir></style></legend>