使用drawBitmap绘制图片
来源:互联网 发布:mysql 1267 编辑:程序博客网 时间:2024/05/18 00:43
用drawBitmap写了个会动的小僵尸
首先是图片资源
自定义View中代码如下
public class ZoombieView extends View { private int width,height; private int intervalW,intervalH; private Paint bitmapPaint; private Bitmap bitmap; private Rect src; private Rect dst; private int currentW=0; private int currentH=0; private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (currentW<10&¤tH==0){ currentW++; invalidate(); sendEmptyMessageDelayed(0,300); }else if (currentW==10&¤tH==0){ currentH++; currentW=0; invalidate(); sendEmptyMessageDelayed(0,300); }else if (currentW<10&¤tH==1){ currentW++; invalidate(); sendEmptyMessageDelayed(0,300); } } }; @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); width=w; height=h; } public ZoombieView(Context context) { this(context,null); } public ZoombieView(Context context, AttributeSet attrs) { super(context, attrs); initView(); } private void initView() { bitmapPaint=new Paint(); bitmapPaint.setAntiAlias(true); bitmapPaint.setDither(true); bitmapPaint.setFilterBitmap(true); bitmap= BitmapFactory.decodeResource(getResources(), R.mipmap.zombie); intervalW=bitmap.getWidth()/11; intervalH=bitmap.getHeight()/2; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.translate(width/2,height/2); src=new Rect(intervalW*currentW,intervalH*currentH,intervalW*(currentW+1),intervalH*(currentH+1)); dst=new Rect(-intervalW/2,-intervalH/2,intervalW/2,intervalH/2); canvas.drawBitmap(bitmap,src,dst,bitmapPaint); if (currentW==0&¤tH==0){ handler.sendEmptyMessageDelayed(0,300); } }}
在布局中引用
<com.example.mytestapplication.widget.ZoombieView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/>
阅读全文
0 0
- 使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- android中Canvas使用drawBitmap绘制图片
- 在使用drawBitmap()将绘制的图片全屏显示
- Android 使用Canvas中的drawBitmap方法绘制拉伸的图片
- 使用canvas.drawBitmap画出的图片能否设置背景色??
- 安卓中drawBitmap绘制图像方法
- android绘制方法----drawBitmap基本用法
- DrawBitmap
- 自定义view-drawBitmap巧妙使用
- canvas.drawBitmap()使图片全屏显示
- canvas.drawBitmap()使图片全屏显示
- 使用CImage绘制半透明图片
- 使用html5 canvas绘制图片
- Android 中Canvas.drawBitmap()的使用
- android 中Canvas使用drawBitmap画图
- 【NOIP2017】SummerTraining0710
- Bootstrap基础4——form表单
- intersection set
- Maven 简单使用创建Web项目
- pyhton爬虫(11)——抓取亚马逊商品类别信息
- 使用drawBitmap绘制图片
- 应届生落户上海申请及办理流程
- HDU1330 Deck
- RocketMQ简介
- tipso插件---消息提示框
- Java线程、并发概念整理
- ios 图片放大缩小动画效果
- springboot学习-全局异常处理
- Linux netstat命令详解