package com.example.and6;import android.annotation.SuppressLint;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.util.AttributeSet;import android.widget.ImageView;public class MeshView  extends ImageView{Bitmap bitmap;//分割成50*50个格int WIDTH=50;int HEIGHT=50;//依次存放每一个点的 x y坐标float[]origs=new float[ ( (WIDTH+1)*(HEIGHT+1)  )*2];float[]verts=new float[origs.length];float k;boolean isStart=false;public MeshView(Context context) {super(context);init();}public MeshView(Context context, AttributeSet attrs) {super(context, attrs);init();}public MeshView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}@SuppressLint("NewApi")public MeshView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr, defStyleRes);init();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);flagWave();k+=0.1f;canvas.drawBitmapMesh(bitmap, WIDTH, HEIGHT, verts, 0, null, 0, null);if (isStart) {invalidate();}}public void startAnim() {isStart=true;requestLayout();}public void stopAnim() {isStart=false;}private void init() {bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic);float bitmapHeight=bitmap.getHeight();float bitmapWidth=bitmap.getHeight();int index=0;for (int y = 0; y <= HEIGHT; y++) {float fy=bitmapHeight*y/HEIGHT;for (int x = 0; x <= WIDTH; x++) {float fx=bitmapWidth*x/WIDTH;origs[index*2+0]=verts[index*2+0]=fx;origs[index*2+1]=verts[index*2+1]=fy;index++;}}}private void flagWave() {for (int j = 0;j <= HEIGHT; j++) {for (int i = 0; i <= WIDTH; i++) {verts[ (j*(WIDTH+1)+i )*2+0 ]+=0;float offsetY=(float) Math.sin( i*1.0f/WIDTH*2*Math.PI + Math.PI*k);//k 实现周期变化verts[ (j*(WIDTH+1)+i )*2+1 ]=origs[ ( j*WIDTH+i )*2+1 ]+offsetY*100; //100 振幅}}}}


更多相关文章

  1. 学个明白--Android世界的坐标系
  2. Android写文件到SDCard的一般过程和代码
  3. Android写文件到SDCard的一般过程和代码
  4. Google API应用
  5. android获取gps坐标
  6. 【Android的从零单排开发日记】之入门篇(三)——Android目录结构
  7. Android(安卓)View滑动
  8. android TextView 容纳不下内容,让字向左滚动的办法
  9. ArcGIS API for Android(安卓)案例教程 17

随机推荐

  1. Android开发之android_apk 在线安装(源代
  2. android 动作处理之手势捕捉
  3. Android解析JSON
  4. android 导出签名APK--混淆文件proguard.
  5. Android Contacts的使用(三)
  6. android traceview and dmtracedump使用
  7. 使用android访问SQLServer数据库
  8. 插件入门,Android(安卓)Studio 生成 Butte
  9. Android浏览器如何打开本地html文件
  10. 设置行距