3D旋转与相机

时间:2017-10-06 19:44:44

标签: android camera rotation

我希望通过此代码使用相机在x和y轴上旋转imageview,它可以正常工作:

protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromXDegrees = mFromXDegrees;
    float Xdegrees = fromXDegrees + ((mToXDegrees - fromXDegrees) * interpolatedTime);
    final float fromYDegrees = mFromYDegrees;
    float Ydegrees = fromYDegrees + ((mToYDegrees - fromYDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    Matrix matrix = t.getMatrix();
    camera.save();
    camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
    camera.rotateX(Xdegrees);
    camera.rotateY(Ydegrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}

但是当我在x和y轴上旋转位图时,结果不好,与此代码旋转的imageview不同:

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

Matrix matrix = new Matrix();
int centerX = width / 2;
int centerY = height / 2;

Camera camera = new Camera();
camera.save();
camera.translate(0.0f, 0.0f, 0.0f);
camera.rotateX(Xdegrees);
camera.rotateY(Ydegrees);
camera.getMatrix(matrix);
camera.restore();

matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);

Bitmap bmOverlay = Bitmap.createBitmap(width, height, sourceBitmap.getConfig());
Paint paint = new Paint();
paint.setFilterBitmap(true);
paint.setAntiAlias(true);
paint.setDither(true);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(sourceBitmap, matrix, paint);

看看这些结果:

第一张图片=主图片

第二张图片= imageview x:20,y:30

第三张图像=位图x:20,y:30

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors

main image

imageview x = 20, y = 30

有什么问题?

0 个答案:

没有答案