现在的位置: 首页 > 综合 > 正文

Android小技巧/bitmap合成

2018年05月26日 ⁄ 综合 ⁄ 共 798字 ⁄ 字号 评论关闭

Java 

Bitmap im1, im2;

//读取第一张图片,大小为500*500
im1 = (Bitmap)Bitmap.FromFile("C:\\1.bmp");
//读取第二张图片,大小为400*400
im2 = (Bitmap)Bitmap.FromFile("C:\\2.bmp");

//替换
for (int i = 0; i < 400; i++)
    for (int j = 0; j < 400; j++)
        im1.SetPixel(i + 50, j + 50, im2.GetPixel(i, j));

Android

	public static Bitmap createBitmap(Bitmap background, Bitmap forground) {
		if (background == null) {
			return null;
		}
		forground = getRoundedCornerBitmap(forground);
		int bgWidth = background.getWidth();
		int bgHeight = background.getHeight();
		int forWidth = forground.getWidth();
		int forHeight = forground.getHeight();
		
		Bitmap newBitmap = Bitmap.createBitmap(bgWidth, bgHeight, Config.ARGB_8888);
		Canvas cv = new Canvas(newBitmap);
		cv.drawBitmap(background, 0, 0, null);
		cv.drawBitmap(forground, (bgWidth - forWidth) / 2, (bgHeight - forHeight) / 2, null);// 在src的右下角画入水印
		cv.save(Canvas.ALL_SAVE_FLAG);
		cv.restore();
		return newBitmap;
	}

抱歉!评论已关闭.