简体   繁体   English

旋转带有多个位图的整个画布的最佳方法?

[英]Best way to rotate the entire canvas with multiple bitmaps?

I have an ImageView with a custom onDraw where I paint a number of bitmaps on some (x,y) coordinates. 我有一个带有自定义onDrawImageView ,在其中我在一些(x,y)坐标上绘制了许多位图。 These bitmaps cannot be changed. 这些位图不能更改。 I want to rotate the entire image by -90 degrees so that the horizontally drawn image is placed vertically. 我想将整个图像旋转-90度,以便将水平绘制的图像垂直放置。 (And yes, this view lives in a portrait mode application.) (是的,此视图位于纵向模式应用程序中。)

I tried a number of variants, both using Canvas.rotate , Canvas.scale and Matrix.postRotate but with no success. 我尝试了多种变体,都使用Canvas.rotateCanvas.scaleMatrix.postRotate但都没有成功。 The rotation is easy, but getting the desired layout seems impossible. 旋转很容易,但是获得所需的布局似乎是不可能的。 My drawn objects are offseted outside the view. 我的绘制对象在视图外部偏移。 I'm obviously doing something wrong with the pivot coordinate or whatever. 我显然在枢轴坐标或其他方面做错了。 Any help is appreciated! 任何帮助表示赞赏!

canvas.rotate(-90.0f, getWidth() / 2, getHeight() / 2);

What is the best solution to rotate a canvas? 旋转画布的最佳解决方案是什么?

See if this helps. 看看是否有帮助。 The Compass.java sample from the API demos does it by using canvas.translate first then canvas.rotate with angle only. API演示中的Compass.java示例通过首先使用canvas.translate然后再仅使用angle.canvas.rotate来实现此目的。

    int w = canvas.getWidth();
    int h = canvas.getHeight();
    int cx = w / 2;
    int cy = h / 2;

    canvas.translate(cx, cy);
    if (mValues != null) {
        canvas.rotate(-mValues[0]);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM