<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="copy" android:text="创建一个图形拷贝"/> <ImageView android:id="@+id/iv1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="@+id/iv2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
package com.wzw.imagecopy; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.os.Bundle; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.view.View; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView imageView1; private ImageView imageView2; private Bitmap srcBm; private Bitmap copyBm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView1=(ImageView) findViewById(R.id.iv1); imageView2=(ImageView) findViewById(R.id.iv2); srcBm=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); imageView1.setImageBitmap(srcBm); //创建原图的一个副本,可以修改图片 copyBm=Bitmap.createBitmap(srcBm.getWidth(), srcBm.getHeight(), srcBm.getConfig()); } /** * 创建原图的一个复制 * @param v */ public void copy(View v){ //准备一个画板 Canvas canvas=new Canvas(copyBm); //准备画笔 Paint paint=new Paint(); paint.setColor(Color.BLACK); //3.开始画 Matrix m=new Matrix();//按照1:1画图 canvas.drawBitmap(srcBm, m, paint);//仿照原图作画 imageView2.setImageBitmap(copyBm); } }
Android开发图形处理创建一个图形的拷贝,布布扣,bubuko.com
原文地址:http://blog.csdn.net/ibey0nd/article/details/38356857