drawBitmapMesh扭曲图片
来源:互联网 发布:中国网络美女排行榜 编辑:程序博客网 时间:2024/04/30 03:54
class GameView extends View{ Bitmap bitmap; final int WEIGHT_COUNT = 20; //宽度拆分数量 final int HEIGHT_COUNT = 20; //高度拆分数量 float[] verts; //扭曲后坐标 float [] olds; //扭曲前坐标 float K = 500000; //扭曲度,该值越大,扭曲的越严重 public GameView(Context context) { super(context); //显示的图片 bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.d)).getBitmap(); int bitWeight = bitmap.getWidth(); int bitHeight = bitmap.getHeight(); //计算分隔出的坐标点数量 int count = (WEIGHT_COUNT + 1)*(HEIGHT_COUNT +1)*2; verts = new float[count]; olds = new float[count]; //计算分隔出的坐标位置 int index = 0; //数组位置 for(int x=0; x<WEIGHT_COUNT; ++x){ //横向坐标 float fx = bitWeight * x /WEIGHT_COUNT; for(int y=0; y<HEIGHT_COUNT; ++y){ //纵向坐标 float fy = bitHeight *y/HEIGHT_COUNT; verts[index] = olds[index] = fx; verts[index + 1] = olds[index + 1] = fy; index += 2; } } } protected void onDraw(Canvas canvas) { super.onDraw(canvas); //画背景 canvas.drawColor(Color.WHITE); //画图像 canvas.drawBitmapMesh(bitmap,WEIGHT_COUNT,HEIGHT_COUNT,verts,0,null,0,null); } public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); for(int i=0; i<olds.length; i+=2){ float oldX = olds[i]; float oldY = olds[i +1]; //得到点到按下地方的距离 (长的平方+宽的平方)开根号 float dx = x-oldX; float dy = y - oldY; float dd = dx*dx + dy*dy; float length = (float)Math.sqrt(dd); //计算扭曲度 float pull = K /(length*dd); //k值除以距离的3次方 if(pull >= 1){ //超过最大扭曲度,将坐标移动到按下的点 verts[i] = x; verts[i+1] = y; }else{ verts[i] = oldX + dx * pull; verts[i + 1] = oldY + dy*pull; } } invalidate(); return true; } }
0 0
- 使用drawBitmapMesh扭曲图片
- drawBitmapMesh扭曲图片
- 使用 drawBitmapMesh 扭曲图片
- Android 图片特效处理:drawBitmapMesh——图像扭曲+动感
- Android drawBitmapMesh 扭曲图像
- Android drawBitmapMesh扭曲图像
- 使用canvas.drawBitmapMesh扭曲图像
- 图形处理 使用drawBitmapMesh扭曲图像
- Android Canvas的drawBitmapMesh实现扭曲图像
- 图片扭曲
- 图片扭曲
- 初学Android,图形图像之使用drawBitmapMesh扭曲图像(三十二)
- android drawBitmapMesh()图片旗帜飘扬效果
- matlab图片扭曲
- Android BitmapMesh使图片扭曲
- ios 图片不被扭曲
- 解决QLabel显示图片扭曲的问题
- C# 图片自由变换 任意扭曲
- OGRE 1.9 的第一个程序(OGRE HelloWorld程序)
- 1.2深入理解嵌套类和内部类
- Android新浪微博第三方登录的一些问题
- codeforces 55E Very simple problem
- 连接池DBCP参数设置
- drawBitmapMesh扭曲图片
- 在tomcat7下停止应用时报错:created a ThreadLocal with key of type
- 重装系统后 如何使用之前mysql数据
- 实战Java虚拟机之一“堆溢出处理”
- Comparison of Germany and China, the industry 4.0 strategy and approach for China 中德比较以及中国工业4.0策略和手段
- TD LTE与FDD LTE 的区别
- 继承ViewGroup重写onMeasure方法的详解
- [php] ob_flush()和flush()解析
- Volatile关键字的作用