点击ImageSwitcher显示的图片即可切换到为美女换衣全屏界面,手指在界面上滑动,滑动处的衣服就被褪掉了,很黄很暴力,大家要hold住呀!!
其实啊这个实现就是两张图片,一张底图,一张上面的图,上面的图都被抹掉了,下面的图就出来了,主要是PorterDuff和PorterDuffXfermode的利用,APIDEMO里面也有相关的介绍。好,贴出主要代码:
package com.picture;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
public class RemoveClothActivity extends Activity {
private int SCREEN_W;
private int SCREEN_H;
private int imagePosition;
private MediaPlayer mp3Player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏
Intent intent = getIntent();
imagePosition = intent.getIntExtra("imagePosition", 0);
initMP3Player();
setContentView(new MyView(this));
}
private void initMP3Player(){
mp3Player = MediaPlayer.create(RemoveClothActivity.this, R.raw.higirl);
mp3Player.setLooping(false);
}
private void playMusic(){
mp3Player.start();
}
class MyView extends View {
private Bitmap mBitmap;
private Canvas mCanvas;
private Paint mPaint;
private Path mPath;
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
public MyView(Context context) {
super(context);
setFocusable(true);
setScreenWH();
setBackGround();
// 1.if icon1 is a image,you can open MENU_ITEM_COMMENT bellow
// Bitmap bm = createBitmapFromSRC();
// if you want to set icon1 image's alpha,you can open
// MENU_ITEM_COMMENT bellow
// bm = setBitmapAlpha(bm, 100);
// if you want to scale icon1 image,you can open MENU_ITEM_COMMENT
// bellow
// bm = scaleBitmapFillScreen(bm);
// 2.if icon1 is color
// Bitmap bm = createBitmapFromARGB(0x8800ff00, SCREEN_W, SCREEN_H);
int drawableId = 0;
try {
drawableId = R.drawable.class.getDeclaredField(
"pre" + imagePosition).getInt(this);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
Bitmap bm = scaleBitmapFillScreen(BitmapFactory.decodeResource(getResources(), drawableId));
seticon1Bitmap(bm);
}
private void setScreenWH() {
// get screen info
DisplayMetrics dm = new DisplayMetrics();
dm = this.getResources().getDisplayMetrics();
// get screen width
int screenWidth = dm.widthPixels;
// get screen height
int screenHeight = dm.heightPixels;
SCREEN_W = screenWidth;
SCREEN_H = screenHeight;
}
private Bitmap createBitmapFromSRC() {
return BitmapFactory.decodeResource(getResources(),
R.drawable.icon1);
}
/**
*
* @param colorARGB
* should like 0x8800ff00
* @param width
* @param height
* @return
*/
private Bitmap createBitmapFromARGB(int colorARGB, int width, int height) {
int[] argb = new int[width * height];
for (int i = 0; i < argb.length; i++) {
argb[i] = colorARGB;
}
return Bitmap.createBitmap(argb, width, height, Config.ARGB_8888);
}
/**
*
* @param bm
* @param alpha
* ,and alpha should be like ox00000000-oxff000000
* @note set bitmap's alpha
* @return
*/
/*
* private Bitmap setBitmapAlpha(Bitmap bm, int alpha) { int[] argb =
* new int[bm.getWidth() * bm.getHeight()]; bm.getPixels(argb, 0,
* bm.getWidth(), 0, 0, bm.getWidth(), bm .getHeight());
*
*
* for (int i = 0; i < argb.length; i++) {
*
* argb[i] = ((alpha) | (argb[i] & 0x00FFFFFF)); } return
* Bitmap.createBitmap(argb, bm.getWidth(), bm.getHeight(),
* Config.ARGB_8888); }
*/
/**
*
* @param bm
* @param alpha
* ,alpha should be between 0 and 255
* @note set bitmap's alpha
* @return
*/
private Bitmap setBitmapAlpha(Bitmap bm, int alpha) {
int[] argb = new int[bm.getWidth() * bm.getHeight()];
bm.getPixels(argb, 0, bm.getWidth(), 0, 0, bm.getWidth(),
bm.getHeight());
for (int i = 0; i < argb.length; i++) {
argb[i] = ((alpha << 24) | (argb[i] & 0x00FFFFFF));
}
return Bitmap.createBitmap(argb, bm.getWidth(), bm.getHeight(),
Config.ARGB_8888);
}
/**
*
* @param bm
* @note if bitmap is smaller than screen, you can scale it fill the
* screen.
* @return
*/
private Bitmap scaleBitmapFillScreen(Bitmap bm) {
return Bitmap.createScaledBitmap(bm, SCREEN_W, SCREEN_H, true);
}
private void setBackGround(){
int drawableId = 0;
try {
drawableId = R.drawable.class.getDeclaredField(
"after" + imagePosition).getInt(this);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
setBackgroundResource(drawableId);
}
/**
*
* @param bm
* @note set icon1 bitmap , which overlay on background.
*/
private void seticon1Bitmap(Bitmap bm) {
// setting paint
mPaint = new Paint();
mPaint.setAlpha(0);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(20);
// set path
mPath = new Path();
;
// converting bitmap into mutable bitmap
mBitmap = Bitmap.createBitmap(SCREEN_W, SCREEN_H, Config.ARGB_8888);
mCanvas = new Canvas();
mCanvas.setBitmap(mBitmap);
// drawXY will result on that Bitmap
// be sure parameter is bm, not mBitmap
mCanvas.drawBitmap(bm, 0, 0, null);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(mBitmap, 0, 0, null);
mCanvas.drawPath(mPath, mPaint);
super.onDraw(canvas);
}
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
playMusic();
break;
}
return true;
}
}
}
- 大小: 378.6 KB
- 大小: 413.2 KB
- 大小: 248.5 KB
- 大小: 307.5 KB
分享到:
相关推荐
一款android开发的帮美女的更衣的小游戏,飞蝗芜湖!!!
这是一款经典的android和游戏源码,供大家一起学习
详细请看我的Android热门应用高仿专栏:http://blog.csdn.net/dawanganban/article/details/20771691
Android removeClothForBeautyGirl_美女更衣安卓游戏Java源码,点击ImageSwitcher显示的图片即可切换到为美女换衣全屏界面,手指在界面上滑动,滑动处的衣服就被褪掉了。其实是两张图片,一张底图,一张上面的图,...
自己写的一款小游戏,相比于其他的相同类型的APP更衣的效率明显提高
android 小游戏 美女密码源码
本项目是一个基于安卓的美女图片项目源码,被作者分成了气质、校花、时尚、素颜、唯美、清纯、可爱、长发、小清新、嫩萝莉等十多个分类,所有图片都是异步通过网络下载,以瀑布流的方式展示。大部分代码有详细的中文...
Android小游戏安卓游戏源码45款合集: 21点游戏源码.rar Angle v1.0.ZIP Barrage_OpenGLES.rar Billiard_2D.zip catcake-0.9.5-android.tar.gz Chess.rar Crackedcarrot.rar CrazyFootBall.zip EggGame.rar Elose-wr....
Android游戏源码安卓美女拼图游戏,初学者可以参考里面的东西,高手也可以看看
本源码是一个妄撮chocolate的安卓版小游戏的项目源码,项目本身比较比较小实现也比较简单,只有四个java文件,源码没有注释,这类游戏用一句话概况就是:挑战裸露极限满足偷窥欲(听起来好吊),就是这样,需要的...
【微信小程序-毕设期末大作业】微信小程序源码 【微信小程序-毕设期末大作业】微信小程序源码 【微信小程序-毕设期末大作业】微信小程序源码 【微信小程序-毕设期末大作业】微信小程序源码 【微信小程序-毕设期末大...
这个源码能让你实现搭建一个看美女图片的微信小程序源码,你可以二次开始,做个流量主,实现广告收益,本源码免费分享,感兴趣的朋友,可以下载搭建使用,使用时要用到备案域名,不懂备案的可以度娘查询
教程名称: 经典Android开发源码之游戏系【】【经典Android游戏源码10】Android钻石迷情源码【】【经典Android游戏源码11】2048小游戏源码【】【经典Android游戏源码12】Android简单炮台塔防小游戏源码【】【经典...
Android游戏源码安卓美女拼图游戏第二版
Android美女拼图源码,可编译运行,有需要的朋友请自行修改。
美女 CASA(高清) 写真图库每日更新,为您的 Android 装置提供 60,000 张高质素美女桌布。 特点: - 浏览超过 60,000张高清美女明星壁纸和背景 - 高清壁纸可以下载至您的 SD Card - 可按日期或下载次数排序 - ...
android美女的秘密源码
Android项目源码之分类美女图片大全