仅在垂直方向上倾斜位图 [英] Skewing a bitmap only in the vertical direction

查看:23
本文介绍了仅在垂直方向上倾斜位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想倾斜(如果这不是正确的词,请纠正我)一个位图,使其看起来有深度.将我所要求的内容可视化的一个好方法是星球大战的学分如何倾斜以显示深度.

I want to skew (correct me if this is not the correct word) a bitmap so that it appears to have depth. A good way to visualize what I am asking for is how the credits of Star Wars are angled to show depth.

我尝试了以下方法:

canvas.getMatrix().postSkew(kx,ky,px,py);

canvas.skew(sx,sy);

但我没有取得太大的成功.上述方法似乎总是将位图转换为平行四边形.有没有办法把位图转成梯形呢?

But I have not had much success. The above methods seem to always transform the bitmap into a parallelogram. Is there a way to transform the bitmap into a trapezoid instead?

这是我从 Romain 指出的示例中提取的一段代码.

Here is a snippet of code that I took from the examples that Romain pointed me to.

canvas.rotate(-mOrientation[0] + mHeading, mCenterX, mCenterY);

camera.save();

if (mReverse) {
    camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
    camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}

camera.rotateX(mOrientation[1]);
camera.applyToCanvas(canvas);
canvas.drawPath(mPath, mPaint);
canvas.drawCircle(mCenterX, mCenterY, mRadius - 37, mPaint);

camera.restore();

推荐答案

使用 skew() 无法达到想要的效果.但是,您可以使用 Camera 对象和 3D 旋转来实现此效果.相机将为您生成一个矩阵,然后您可以将其应用到画布上.请注意,结果不会是透视正确的,但足以满足您的目的.例如,这是在 Honeycomb 的启动器(以及许多其他应用程序)中完成 3D 旋转的方式.

You cannot achieve the effect you want with skew(). However, you can use a Camera object and 3D rotations to achieve this effect. The Camera will generate a Matrix for you that you can then apply on the Canvas. Note that the result will not be perspective correct, but good enough for your purpose. This how 3D rotations are done in Honeycomb's Launcher for instance (and many other apps.)

这篇关于仅在垂直方向上倾斜位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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