撕开美女的衣服

public class MainActivity extends Activity {

	private ImageView iv_back;
	private ImageView iv_up;
	private Bitmap alterBitmap;
	private Canvas canvas;
	private Paint paint;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		iv_back = (ImageView)findViewById(R.id.iv_back);
		iv_up = (ImageView)findViewById(R.id.iv_up);
		
		BitmapFactory.Options opts = new Options();
		//opts.inSampleSize = 2;
		
		Bitmap back = BitmapFactory.decodeResource(getResources(), 
				R.drawable.g16_back, opts);
		//只读图片
		Bitmap up = BitmapFactory.decodeResource(getResources(), 
				R.drawable.g16_up, opts);
	
		//可以修改的空白bitmap,mutable
		alterBitmap = Bitmap.createBitmap(up.getWidth(), 
				up.getHeight(), up.getConfig());
		canvas = new Canvas(alterBitmap);
		paint = new Paint();
		paint.setStrokeWidth(5);
		paint.setColor(Color.BLACK);
		canvas.drawBitmap(up, new Matrix(), paint);
		
		iv_back.setImageBitmap(back);
		iv_up.setImageBitmap(alterBitmap);
		
		
		iv_up.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				
				switch(event.getAction()){
				case MotionEvent.ACTION_DOWN:
					
					break;
					
				case MotionEvent.ACTION_MOVE:
					int newX = (int) event.getX();
					int newY = (int) event.getY();
					int xx, yy;
					for(int i=-8; i<=8; i++){
						for(int j=-8; j<=8; j++){
						
							alterBitmap.setPixel(xx, yy, Color.TRANSPARENT);
						}
					}
					iv_up.setImageBitmap(alterBitmap);
					
					break;
				}
				return true;
			}
		});
	}
}


<FrameLayout 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_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        />

    <ImageView
        android:id="@+id/iv_up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

</FrameLayout>


展开阅读全文

没有更多推荐了,返回首页