Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2621349
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: Android平台

2014-11-17 00:51:07



来自黑马:


///< 脱衣服

点击(此处)折叠或打开

  1. package com.errorvenus.undress;

  2. import android.support.v7.app.ActionBarActivity;
  3. import android.graphics.Bitmap;
  4. import android.graphics.Bitmap.Config;
  5. import android.graphics.BitmapFactory;
  6. import android.graphics.Canvas;
  7. import android.graphics.Color;
  8. import android.graphics.Matrix;
  9. import android.graphics.Paint;
  10. import android.os.Bundle;
  11. import android.view.MotionEvent;
  12. import android.view.View;
  13. import android.view.View.OnTouchListener;
  14. import android.widget.ImageView;

  15. public class MainActivity extends ActionBarActivity {

  16.     private ImageView img = null;
  17.     private Bitmap bitmapAlert = null;
  18.     private Canvas canvas = null;
  19.     private Paint paint = null;

  20.     @Override
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_main);

  24.         img = (ImageView) findViewById(R.id.undressImg);
  25.         Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.g3_up);

  26.         ///< 必须设置图片格式,否则会全黑
  27.         bitmapAlert = Bitmap.createBitmap(
  28.                 bitmap.getWidth(),
  29.                 bitmap.getHeight(),
  30.                 Config.ARGB_4444);
  31.         canvas = new Canvas(bitmapAlert);
  32.         paint = new Paint();
  33.         paint.setColor(Color.BLACK);
  34.         canvas.drawBitmap(bitmap, new Matrix(), paint);
  35.         img.setImageBitmap(bitmapAlert);

  36.         img.setOnTouchListener(new OnTouchListener() {

  37.             @Override
  38.             public boolean onTouch(View v, MotionEvent event) {
  39.                 // TODO Auto-generated method stub
  40.                 switch (event.getAction())
  41.                 {
  42.                 case MotionEvent.ACTION_MOVE: ///< 崩溃是需要处理边界问题
  43.                     int x = (int) event.getX();
  44.                     int y = (int) event.getY();
  45.                     for (int i = -4; i < 5; i++)
  46.                     {
  47.                         for (int j = -4; j < 5; j++)
  48.                         {
  49.                             bitmapAlert.setPixel(x + i, y + j, Color.TRANSPARENT);
  50.                         }
  51.                     }
  52.                     img.setImageBitmap(bitmapAlert);
  53.                     //bitmapAlert.setPixel(x, y, Color.TRANSPARENT);
  54.                     //img.setImageBitmap(bitmapAlert);
  55.                     //                        canvas.drawCircle(event.getX(), event.getY(), 2f, paint);
  56.                     //                        img.setImageBitmap(bitmapAlert);
  57.                     break;
  58.                 }

  59.                 return true;
  60.             }
  61.         });
  62.     }
  63. }



阅读(1662) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~