庹庹

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
package tuo.demo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.widget.ImageView;

public class MyCanvasActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView iv=(ImageView)findViewById(R.id.iv_test);
        iv.setImageBitmap(getNewBitmap());
    }

    Bitmap getNewBitmap() {
        Bitmap bitmap1;
        Bitmap bitmap2;
        bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.src);
        bitmap2 = BitmapFactory.decodeResource(getResources(),
                R.drawable.overlay);
        int w = bitmap1.getWidth();
        int h = bitmap1.getHeight();
        int ww = bitmap2.getWidth();
        int wh = bitmap2.getHeight();
        Bitmap newb = Bitmap.createBitmap(w, h, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
        Canvas cv = new Canvas(newb);
        cv.drawBitmap(bitmap1, 0, 0, null);// 在 0,0坐标开始画入src
        cv.drawBitmap(bitmap2, 15, h-wh, null);
        cv.save(Canvas.ALL_SAVE_FLAG);// 保存
        // store
        cv.restore();// 存储
        return newb;
    }
}
posted on 2012-08-29 11:25  庹林  阅读(263)  评论(0编辑  收藏  举报