旋转图像围绕指定的点也不行! (安卓) [英] Rotating an image around a specified point doesn't work! (Android)

查看:138
本文介绍了旋转图像围绕指定的点也不行! (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林旋转与postRotate一个ImageView的(浮度,浮像素,浮子PY),设定像素和吡到几个不同的充值,包括(0,0)和(imgView.getHeight(),imgView.getWidth() ),但它拒绝绕任何其它点比中心。我想知道是否它有什么关系的事实,我的重心是在的LinearLayout中心?

I'm rotating an ImageView with postRotate(float degrees, float px, float py), setting px and py to a few differnt values including (0,0) and (imgView.getHeight(),imgView.getWidth()) but it refuses to rotate around any other point than the center. I'm wondering whether it's got anything to do with the fact that my gravity is center in the LinearLayout?

我的布局:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">

    <ImageView
        android:id="@+id/imageTraj"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="matrix"
        android:src="@drawable/impactangle" />

我如何旋转图像:

matrix.postRotate(degrees,imageView.getHeight(),imageView.getWidth());
imageView.setImageBitmap(Bitmap.createBitmap(imageScaled, 0, 0,
                imageScaled.getWidth(), imageScaled.getHeight(), matrix, true));

PS我注意到有几个类似的问题,但他们都没有合适的答案。

PS I've noticed there are a few similar questions, but none of them have suitable answers.

推荐答案

我使用的是自定义的的ImageView 我的设置角度的旋转。

I am using a custom ImageView where I set the angle rotation.

public class CompassImage extends ImageView {
    private float angleRotation;

    public CompassImage(Context context) {
        super(context);
    }

    public CompassImage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CompassImage(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setAngleRotation(float angleRotation) {
        this.angleRotation = angleRotation;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Rect clipBounds = canvas.getClipBounds();
        canvas.save();
        canvas.rotate(angleRotation, clipBounds.exactCenterX(), clipBounds.exactCenterY());
        super.onDraw(canvas);
        canvas.restore();
    }
}

如果你玩弄clipBounds您可能会发现有用的。

If you play around with clipBounds you may find that helpful.

这篇关于旋转图像围绕指定的点也不行! (安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆