在内存中创建原图的副本

* Android系统要求原图是只读的,只能修改副本
* 编写步骤:
  1. 加载原图
  2. 笔
  3. 纸
  4. 板
  5. 作画

package com.example.copy;
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.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ImageView iv = (ImageView) findViewById(R.id.copy);
      //获取副本的源图片
      Bitmap srcbmp = BitmapFactory.decodeResource(getResources()   , R.drawable.year);
      //获取画笔
      Paint paint = new Paint();
      //创建副本
      Bitmap copybmp = Bitmap.createBitmap(srcbmp.getWidth(), srcbmp.getHeight(), srcbmp.getConfig());
      //获取画布
      Canvas canvas = new Canvas(copybmp);
      //绘画
      canvas.drawBitmap(srcbmp, new Matrix(), paint);
      //显示图片
      iv.setImageBitmap(copybmp);
   }
}

 

posted on 2017-02-20 20:30  LoaderMan  阅读(307)  评论(0编辑  收藏  举报

导航