Androidテクニック/bitmap合成

1055 ワード

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;
	}