发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及混凝土泵车等,在成都网站建设、营销型网站、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。> 1 package cn.itcast.bitmapcopy;
2
3 import java.io.FileNotFoundException;
4
5 import android.app.Activity;
6 import android.content.Intent;
7 import android.graphics.Bitmap;
8 import android.graphics.BitmapFactory;
9 import android.graphics.Canvas;
10 import android.graphics.ColorMatrix;
11 import android.graphics.ColorMatrixColorFilter;
12 import android.graphics.Matrix;
13 import android.graphics.Paint;
14 import android.graphics.PorterDuffXfermode;
15 import android.net.Uri;
16 import android.os.Bundle;
17 import android.view.View;
18 import android.widget.ImageView;
19
20 public class DemoActivity extends Activity {
21 private ImageView iv;
22
23 @Override
24 public void onCreate(Bundle savedInstanceState) {
25 super.onCreate(savedInstanceState);
26 setContentView(R.layout.main);
27 iv = (ImageView) findViewById(R.id.iv);
28
29 }
30
31
32 public void selectImage(View view){
33 Intent intent = new Intent();
34 intent.setAction("android.intent.action.PICK");
35 intent.addCategory("android.intent.category.DEFAULT");
36 intent.setType("image/*");
37 startActivityForResult(intent, 0);
38 }
39
40 @Override
41 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
42 try {
43 if (data != null) {
44 // 得到点击图片的uri45 Uri uri = data.getData();
46 //原图47 Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
48
49 //原图的拷贝50 Bitmap alterBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
51 //以拷贝图片的为模板创建一个画布52 Canvas canvas = new Canvas(alterBitmap);
53 Matrix matrix = new Matrix();
54
55 Paint paint = new Paint();
56
57 Bitmap logo = BitmapFactory.decodeResource(getResources(), R.raw.ic_launcher);
58
59
60 canvas.drawBitmap(bitmap, matrix, paint);
61 //指定了两个图片合成的方式62 paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_OVER));
63
64 canvas.drawBitmap(logo, matrix, paint);
65
66
67 iv.setImageBitmap(alterBitmap);
68 }
69 } catch (FileNotFoundException e) {
70 e.printStackTrace();
71 }
72 super.onActivityResult(requestCode, resultCode, data);
73 }
74 }
效果就是两张图片合成一张图片
网站栏目:图片的合成-创新互联
浏览路径:
http://bzwzjz.com/article/ejdih.html