understanding drawBitmapMesh on android
2010-09-24 20:52
976 查看
The ,%20int,%20int[],%20int,%20android.graphics.Paint%29]Canvas.drawBitmapMesh method on android is a like a mystery to me while I looked at the BitmapMesh sample. Though I tried to get some hints from the official document, it didn't help much. After played it with several tests, I got some ideas about how it worked.
A metaphor
The effect of drawBitmapMesh can be thought as pinching a point of an elastic canvas, and pull it to another point. The distorted image is very similar to what we shall get through drawBitmapMesh. Like the figures below show.
![](http://farm5.static.flickr.com/4090/5020393518_ddb1a61fde.jpg)
![](http://farm5.static.flickr.com/4084/5020393526_b92b04c338.jpg)
How the mesh affects the bitmap
The bitmap to be drawn is divided into equal size blocks. And the division is defined by the mesh, which is a float array. The array defines the lines that divide the bitmap. To have a division of W*H blocks, there needs to be (W+1)*(H+1) lines. These lines intersect at (W+1)*(H+1) points. Every two consecutive elements in the array corresponds to the x coordinate and y coordinate of an intersection. So, the mesh array comprises of 2*(W+1)*(H*1) elements. Given the bitmap's size is known, the drawing engine can find out the x and y coordinates of intersections by dividing the width or height of the image to W or H, respectively. So, if the x and y coordinates of an intersection supplied in the mesh doesn't equal to its intact values, the drawing engine will "pinch and pull" the intersection from its original location to the location we define.
Keep in mind that for a intersection that deviates its original location, only those four blocks that around it will be affected. All other blocks that are more than one blocks away from the intersection will remain intact.
A metaphor
The effect of drawBitmapMesh can be thought as pinching a point of an elastic canvas, and pull it to another point. The distorted image is very similar to what we shall get through drawBitmapMesh. Like the figures below show.
![](http://farm5.static.flickr.com/4090/5020393518_ddb1a61fde.jpg)
![](http://farm5.static.flickr.com/4084/5020393526_b92b04c338.jpg)
How the mesh affects the bitmap
The bitmap to be drawn is divided into equal size blocks. And the division is defined by the mesh, which is a float array. The array defines the lines that divide the bitmap. To have a division of W*H blocks, there needs to be (W+1)*(H+1) lines. These lines intersect at (W+1)*(H+1) points. Every two consecutive elements in the array corresponds to the x coordinate and y coordinate of an intersection. So, the mesh array comprises of 2*(W+1)*(H*1) elements. Given the bitmap's size is known, the drawing engine can find out the x and y coordinates of intersections by dividing the width or height of the image to W or H, respectively. So, if the x and y coordinates of an intersection supplied in the mesh doesn't equal to its intact values, the drawing engine will "pinch and pull" the intersection from its original location to the location we define.
Keep in mind that for a intersection that deviates its original location, only those four blocks that around it will be affected. All other blocks that are more than one blocks away from the intersection will remain intact.
相关文章推荐
- Android图形图画学习(7)——drawBitmapMesh
- 初学Android,图形图像之使用drawBitmapMesh扭曲图像(三十二)
- Android图像处理(五)镜像、倒影、drawBitmapMesh实现旗帜飘扬效果
- android drawBitmapMesh
- Android:使用drawBitmapMesh方法产生水波(一)
- Android Canvas的drawBitmapMesh实现扭曲图像
- android drawBitmapMesh()图片旗帜飘扬效果
- Android 图片特效处理:drawBitmapMesh——图像扭曲+动感
- Android之图像处理drawBitmapMesh
- android drawBitmapMesh and drawVertices
- How to draw bitmap on the form - 如何在窗体上画(贴)位图
- Android Api Demos登顶之路(六十九)Graphics-->Bitmap Mesh
- Android drawBitmap 滤除背景色
- Android Canvas使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- android_63_drawBitmap_canvas
- Android基础入门教程——8.3.18 Canvas API详解(Part 3)Matrix和drawBitmapMash
- Android canvas.drawBitmap实现透明效果