android drawBitmapMesh()图片旗帜飘扬效果
来源:互联网 发布:人工智能坏处英语作文 编辑:程序博客网 时间:2024/05/02 01:05
package com.moredo.drawbitamp;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
@SuppressLint(“DrawAllocation”)
public class FlagGril extends View {
private Context mContext;///< 上下文环境
private Bitmap bm;///< 图片
private final int HEIGHT = 100;///< 竖着的网格数
private final int WIDTH = 100;///< 横着的网格数
private float[] orig,verts;///< 原始坐标点,改变后的坐标点
private int A = 30;///< 波动的力度
private float k = 1;
public FlagGril(Context context) {
super(context);
this.mContext = context;
bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gril);
orig = new float[(HEIGHT + 1) * (WIDTH + 1) * 2];
verts = new float[(HEIGHT + 1) * (WIDTH + 1) * 2];
///< 初始化坐标
initOrig();
}
private void initOrig(){ ///< 获取位图的宽高 float width = bm.getWidth(); float height = bm.getHeight(); int index = 0 ; for(int y = 0 ; y <= HEIGHT ;y++) { ///< 纵坐标 float fy = height * y / HEIGHT; for(int x = 0;x <= WIDTH ; x++) { ///< 横坐标 float fx = width * x / WIDTH ; orig[index * 2 + 0] = verts[index * 2 +0] = fx; ///< 在这里人为将坐标加100是为了让图像下移,避免扭曲后被屏幕遮挡 orig[index * 2 + 1] = verts[index * 2 + 1] = fy + 100; index += 1; } }}/** * @fun 波动 * 改变纵坐标的值,横坐标不变 */private void flagWavr(){ 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((float)i / WIDTH * 2 * Math.PI + Math.PI * k); verts[(j * (WIDTH + 1) + i) * 2 + 1] =orig[(j * WIDTH + i) * 2 + 1] +offsetY *A; } }}@Overrideprotected void onDraw(Canvas canvas) { // TODO Auto-generated method stub flagWavr(); k += 0.1F; canvas.drawBitmapMesh(bm, WIDTH, HEIGHT, verts, 0, null, 0, null); invalidate();// canvas.drawBitmap(bm, 0, 0, new Paint());}
}
- android drawBitmapMesh()图片旗帜飘扬效果
- Android图像处理(五)镜像、倒影、drawBitmapMesh实现旗帜飘扬效果
- 愿自由开放的旗帜高高飘扬
- opengles特效之飘扬的旗帜
- opengles特效之飘扬的旗帜
- Android实现飘动的旗帜效果实例
- android drawBitmapMesh
- 普通的日子里哪儿有旗帜飘扬?
- Android 图片特效处理:drawBitmapMesh——图像扭曲+动感
- 使用drawBitmapMesh扭曲图片
- drawBitmapMesh扭曲图片
- 使用 drawBitmapMesh 扭曲图片
- understanding drawBitmapMesh on android
- android drawBitmapMesh and drawVertices
- Android drawBitmapMesh 扭曲图像
- 响铃:飘扬在德国的海尔旗帜是中国制造的世纪跨越
- Android中DrawBitmapMesh用法小记
- Android drawBitmapMesh扭曲图像
- linux学习笔记(一) WIN10下安装ubuntu双系统
- 年龄排序9
- 大臣的旅费---Floyd
- 日期时间选择控件
- NSObject的方法说明
- android drawBitmapMesh()图片旗帜飘扬效果
- 学习篇---progressbar
- redis-命令返回值
- 满二叉树、完全二叉树、平衡二叉树、哈夫曼树
- ContentProvider基本使用(1)
- qsort与sort的使用方法(比较函数详析)
- webstorm预览时把浏览器地址localhost改成IP
- Struts2的第一个程序
- 堆和栈的区别