如何扭曲图像以任何四边形? [英] How to distort an image to any quadrangle?
问题描述
做任何你有一个想法,如何歪曲任何四边形的形象呢? 我想实现的图像,你可以拉任何一个角落的任何方向,扭曲的图像。任何人有一个想法如何做到这一点?我用现在写的东西,在Android的一段时间,但它似乎并不像Android有一个函数,该函数。我真的不觉得自己写一个新的数学库。)
Do any of you have an idea, how to distort an image in any quadrangle? I want to implement an image, which you can pull any corner in any direction, distorting the image. Anyone has an idea how to do that? I use and write stuff in android for a while now, but it does not seem like android has a function for that. I don't really feel like writing a new math library :).
问候, 能否
推荐答案
<打击>看起来像你需要 Canvas.drawBitmapMesh 一>。有一个在Android SDK中的示例展示如何使用它。击>
Looks like you need Canvas.drawBitmapMesh . There is a sample in Android SDK showing how to use it.
您需要使用矩阵
有关画布
绘制位图。您可以轻松地创建一个适合你的位图图像与 Matrix.polyToPoly 的方法,任何四合院这样的转变。它看起来是这样的:
You need to use Matrix
for drawing your bitmap on Canvas
. You can easily create such transformation which will fit your bitmap image into any quadrangle with Matrix.polyToPoly method. It will look like this:
matrix.setPolyToPoly(
new float[] {
0, 0,
bitmap.getWidth(), 0
0, bitmap.getHeight(),
bitmap.getWidth(), bitmap.getHeight()
}, 0,
new float[] {
x0, y0,
x1, y1,
x2, y2,
x3, y3
}, 0,
4);
canvas.drawBitmap(bitmap, matrix, paint);
当X0-X3,Y0-Y3是你的四边形顶点坐标。
Where x0-x3, y0-y3 are your quadrangle vertex coordinates.
这篇关于如何扭曲图像以任何四边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!