码迷,mamicode.com
首页 > 其他好文 > 详细

018_02图片水印

时间:2015-06-01 11:21:26      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:

 

 

 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 }

 

018_02图片水印

标签:

原文地址:http://www.cnblogs.com/woodrow2015/p/4542660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!