标签:
1 package com.example.day18_02picturemark; 2 3 import android.app.Activity; 4 import android.graphics.Bitmap; 5 import android.graphics.BitmapFactory; 6 import android.graphics.Paint; 7 import android.graphics.Bitmap.Config; 8 import android.graphics.Canvas; 9 import android.graphics.PorterDuff.Mode; 10 import android.graphics.PorterDuffXfermode; 11 import android.os.Bundle; 12 import android.view.View; 13 import android.widget.ImageView; 14 15 public class MainActivity extends Activity { 16 17 private ImageView iv_picture; 18 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_main); 23 24 iv_picture = (ImageView) findViewById(R.id.iv_pricture); 25 } 26 27 28 public void addmark(View v){ 29 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.wenzhang); 30 Bitmap mark = BitmapFactory.decodeResource(getResources(), R.drawable.mark); 31 32 Bitmap blank = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Config.ARGB_8888); 33 Canvas canvas = new Canvas(blank); 34 Paint paint = new Paint(); 35 36 canvas.drawBitmap(bitmap, 0, 0, paint); 37 38 39 // 设置图片相交的模式为: darken(上面的和下面的图片都可以显示, 并且相交的部分会有透明) 40 41 int left = bitmap.getWidth() / 2 - mark.getWidth() / 2; 42 int top = bitmap.getHeight() / 2 - mark.getHeight() / 2; 43 44 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER)); 45 canvas.drawBitmap(mark, left,top, paint); 46 47 iv_picture.setImageBitmap(blank); 48 } 49 }
标签:
原文地址:http://www.cnblogs.com/woodrow2015/p/4542660.html