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

图片合适

时间:2016-04-02 12:15:00      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

 1 package com.example.imagecombin;
 2 
 3 import android.os.Bundle;
 4 import android.app.Activity;
 5 import android.graphics.Bitmap;
 6 import android.graphics.BitmapFactory;
 7 import android.graphics.Canvas;
 8 import android.graphics.Color;
 9 import android.graphics.Matrix;
10 import android.graphics.Paint;
11 import android.graphics.PorterDuffXfermode;
12 import android.view.Menu;
13 import android.widget.ImageView;
14 
15 public class MainActivity extends Activity {
16 
17     @Override
18     protected void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20         setContentView(R.layout.activity_main);
21         
22         ImageView iv = (ImageView)findViewById(R.id.iv);
23         Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.bb);
24         Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.aa);
25         Bitmap alterBitmap = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig());//创建可以修改的bitmap
26         Canvas canvas = new Canvas(alterBitmap);
27         
28         Paint paint = new Paint();
29         paint.setColor(Color.BLACK);
30         //这个是设置图片的合成模式
31         paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DARKEN));
32         //paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_OVER));
33         canvas.drawBitmap(bitmap1, new Matrix(), paint);
34         canvas.drawBitmap(bitmap2, new Matrix(), paint);
35         iv.setImageBitmap(alterBitmap);
36     }
37     
38 }

 

图片合适

标签:

原文地址:http://www.cnblogs.com/zhongyinghe/p/5347272.html

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