因为加载到手机中的图片都是只读的不能修改。我们想要修改它可以复制出来一个,在复制的图片上进行修改,原图就不要了。
package com.example.copyimage; import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.view.Menu; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView src; private ImageView copy; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Bitmap bitmapsrc = BitmapFactory.decodeFile("sdcard/IMG_1392.JPG"); //这是一张只有宽高和配置的白纸 Bitmap bitmapcopy = Bitmap.createBitmap(bitmapsrc.getWidth(), bitmapsrc.getHeight(), bitmapsrc.getConfig()); //画笔 Paint paint = new Paint(); //画板,并且把纸铺在画板上 Canvas canvas = new Canvas(bitmapcopy); //开始作画,按照原图绘画 canvas.drawBitmap(bitmapsrc, new Matrix(), paint); src = (ImageView) findViewById(R.id.src); copy = (ImageView) findViewById(R.id.copy); src.setImageBitmap(bitmapsrc); copy.setImageBitmap(bitmapcopy); } }