撕開美女的衣服

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>


發佈了113 篇原創文章 · 獲贊 33 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章