仅在垂直方向偏移的位图 [英] Skewing a bitmap only in the vertical direction
问题描述
我想,这样它似乎有深度偏移(纠正我,如果这是不正确的字)的位图。想象我所要求的一个好方法是星球大战的信用如何角度展现深度。
我已经试过如下:
canvas.getMatrix()postSkew(KX,KY,PX,PY)。
和
canvas.skew(SX,SY);
但我还没有取得很大的成功。上述方法似乎总是转换位图到一个平行四边形。有没有一种方法来转换位图到梯形呢?
下面是code的一个片段,我从罗曼指出的例子带我去。
canvas.rotate(-mOrientation [0] + mHeading,mCenterX,mCenterY);
camera.save();
如果(mReverse){
camera.translate(0.0,0.0,mDepthZ * interpolatedTime);
} 其他 {
camera.translate(0.0,0.0,mDepthZ *(1.0F - interpolatedTime));
}
camera.rotateX(mOrientation [1]);
camera.applyToCanvas(画布);
canvas.drawPath(的mpath,mPaint);
canvas.drawCircle(mCenterX,mCenterY,mRadius - 37,mPaint);
camera.restore();
您无法实现与歪斜你想要的效果()。但是,您可以使用Camera对象和3D旋转来达到这种效果。相机会生成一个矩阵你,你就可以申请在画布上。请注意,结果将不正确的观点,但对你来说已经足够了。这是如何的3D旋转在蜂窝的启动,例如做(和许多其他应用程序。)
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.
I have tried the following:
canvas.getMatrix().postSkew(kx,ky,px,py);
and
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?
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();
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屋!