java - 位图的定位

标签 java android live-wallpaper

当我旋转位图时,它会旋转,但它会在屏幕上不断移动并同时旋转。我想让它在中心旋转?我的代码如下。

try {
    c = holder.lockCanvas();
    // clear the canvas
    c.drawColor(Color.BLACK);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); 
    if (c != null) {

        int width=c.getWidth();
        int height=c.getHeight();

        c.drawBitmap(backgroundImage, 0, 0, null);
        Matrix transform = new Matrix();
        Matrix transform1=new Matrix();

        transform.setRotate(degree, width/2,height/2);
        c.drawBitmap(image1, transform, null);
        //canvas.rotate(-90);

        degree+=5;
        c.restore(); 
    }
}

最佳答案

试试这个代码..

            c = holder.lockCanvas();
            c.drawColor(Color.BLACK);
            Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); 
              if (c != null)
                  {
                    int width=c.getWidth();
                    int height=c.getHeight();
                    c.drawBitmap(backgroundImage, 0, 0, null);

                     Matrix matrix = new Matrix();

                     float px = width/2;

                     float py = height/2;

                     matrix.postTranslate(-image1.getWidth()/2, -image1.getHeight()/2);

                     matrix.postRotate(degree);

                     matrix.postTranslate(px, py);

                     c.drawBitmap(image1, matrix, paint);

                      degree+=5;

                       c.restore(); 
          }

关于java - 位图的定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23372278/

相关文章:

Java 泛型为什么需要通配符(问号)?

java - 线程 "main"java.lang.NoSuchMethodError : main - how to fix it? 中出现异常

java - System.nanoTime() 是否保证返回唯一值?

android - 在 fragment 中添加 Google Maps API V2

android - 如何将视频播放为动态壁纸 android?

macos - 来自 root 的 mac os java 版本不同

android - Android 应用程序错误

Android 联系人 - 自定义字段图标未在 Android 6 中显示

android - 使用 FrameLayout 作为动态壁纸

Android Permission Denial 启动Intent for Wallpaper Settings