资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

创建一个位图的拷贝-创新互联

也是直接上代码吧=。=创建一个位图的拷贝
 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.Matrix;
11 import android.graphics.Paint;
12 import android.net.Uri;
13 import android.os.Bundle;
14 import android.view.View;
15 import android.widget.ImageView;
16 
17 public class DemoActivity extends Activity {
18   private ImageView iv,iv_copy;
19 
20     @Override
21   public void onCreate(Bundle savedInstanceState) {
22 super.onCreate(savedInstanceState);
23         setContentView(R.layout.main);
24         iv = (ImageView) findViewById(R.id.iv);
25         iv_copy = (ImageView) findViewById(R.id.iv_copy);
26         
27     }
28     
29     
30   public void selectImage(View view){
31         Intent intent = new Intent();
32         intent.setAction("android.intent.action.PICK");
33         intent.addCategory("android.intent.category.DEFAULT");
34         intent.setType("image/*");
35         startActivityForResult(intent, 0);
36     }
37     
38     
39     @Override
40   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
41 try {
42  if (data != null) {
43   // 得到点击图片的uri44                 Uri uri = data.getData();
45   //原图46                 Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
47                 iv.setImageBitmap(bitmap);
48   //原图的拷贝49                 Bitmap alterBitmap  = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), bitmap.getConfig());
50   //以拷贝图片的为模板创建一个画布51                 Canvas canvas = new Canvas(alterBitmap);
52                 canvas.drawBitmap(bitmap, new Matrix(), new Paint());
53                 iv_copy.setImageBitmap(alterBitmap);
54             }
55         } catch (FileNotFoundException e) {
56             e.printStackTrace();
57         }
58 super.onActivityResult(requestCode, resultCode, data);
59     }
60 }

新闻名称:创建一个位图的拷贝-创新互联
当前路径:http://cdkjz.cn/article/heogh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220