宅男神器——撕衣服
来源:互联网 发布:origin for mac破解版 编辑:程序博客网 时间:2024/04/26 12:54
给大家介绍一个简单的好玩的app应用程序--撕衣服
思路:
一、在布局文件中:
在中间放两张图片,上面一张为原图(撕衣服之前)的拷贝,下面一张为撕衣服之后的图片
二、在MainActivity中:
关心上面一张图片即撕衣服之前的控件,通过位图工厂获取它的位图,拷贝位图,然后创建画板和画笔,开始作画,然后将拷贝并画好的位图放到原图的位置上。
给原图的拷贝的控件设置屏幕触摸监听事件,匿名内部类的方法重写onTouch方法,最后return true(事件结束被消费掉了)
在src的Java代码 com.mycode.takeoff.MainActivity
import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView iv_pre; private Bitmap alterBitmap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv_pre = (ImageView) findViewById(R.id.iv_pre); // 原图. Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.pre);//原图的位图 alterBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); //原图位图的拷贝 Canvas canvas = new Canvas(alterBitmap); //创建画板 Paint paint = new Paint(); //创建画笔 canvas.drawBitmap(bitmap, new Matrix(), paint); //开始作画 iv_pre.setImageBitmap(alterBitmap); //上面一张图片为撕衣服之前拷贝后的图片 iv_pre.setOnTouchListener(new OnTouchListener() { //屏幕触摸监听事件 int x; int y; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //手指按上去的时候 x = (int) event.getX(); //得到X方向的值 y = (int) event.getY(); //得到Y方向的值 for(int i=-3;i<4;i++){ for(int j=-3;j<4;j++){ if(Math.sqrt(i*i+j*j)<=3){ //设置点击触摸后的原图像素为矩形透明且矩形半径的值不大于3 try { alterBitmap.setPixel(x+i, y+j, Color.TRANSPARENT); } catch (Exception e) { e.printStackTrace(); } } } } iv_pre.setImageBitmap(alterBitmap); break; case MotionEvent.ACTION_MOVE: //手指在屏幕上移动的时候 x = (int) event.getX(); y = (int) event.getY(); for(int i=-3;i<4;i++){ for(int j=-3;j<4;j++){ if(Math.sqrt(i*i+j*j)<=3){ try { alterBitmap.setPixel(x+i, y+j, Color.TRANSPARENT); } catch (Exception e) { e.printStackTrace(); } } } } iv_pre.setImageBitmap(alterBitmap); break; case MotionEvent.ACTION_UP: //手指离开屏幕的时候 break; } return true;// 事件结束被消费掉了 } }); } }
在res/layout/activity_main.xml的代码实现
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ImageView android:id="@+id/iv_after" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/after" /> <ImageView android:id="@+id/iv_pre" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> </RelativeLayout>
1 0
- 宅男神器——撕衣服
- 从“宅男神器:快速播放”谈HDFS的存储
- 撕衣服
- 原创专题———衣服
- 二级c++—对象和衣服
- 爱情——技术宅男另类表达
- Hust oj 1861 猥琐宅男——koko(DP)
- 宅男
- android开发笔记之多媒体—撕衣服(开心一下)
- 撕衣服小游戏代码
- 撕衣服小游戏原理
- 撕衣服源码
- 撕衣服小案例
- 衣服还要一件一件穿——装饰模式
- 衣服还要一件一件穿——装饰模式
- 扒美女衣服——妄撮游戏实现原理
- 【Unity Shaders】Lighting Models —— 衣服着色器
- 转载:很强大—叠衣服打领带系鞋带
- 欢迎使用CSDN-markdown编辑器
- Spring_quartz定时调度
- T4模板配合Dapper生成Model层,包括Insert、Update、Delete、GetList方法
- C++全局变量的声明与定义
- 解决tableview上按钮点击效果的延迟现象
- 宅男神器——撕衣服
- (转)springmvc 文件下载上传典型代码
- 继承
- Android代码中设置图片,文本自定义颜色,Linearlayout等控件设置背景
- 坐标详解之ScrollTo和ScrollBy<一>
- 小白的python笔记
- 浏览器自动化工具-Selenium
- JAVA_OPTS配置实例
- 【PHP】你知道在PHP中的GetType和SetType的区别吗?