Android:从两个位图创建图像,位图下的位图
我想要的:使用两个位图创建图像,在第一个位图下放置第二个位图。Android:从两个位图创建图像,位图下的位图,android,bitmap,android-bitmap,android-image,createbitmap,Android,Bitmap,Android Bitmap,Android Image,Createbitmap,我想要的:使用两个位图创建图像,在第一个位图下放置第二个位图。 此时我使用此代码 public static Bitmap combineImages(Bitmap background, Bitmap foreground, float disFromTheTopPercent) { int width = background.getWidth(), height = background.getHeight(); Bitmap cs = Bitmap.c
此时我使用此代码
public static Bitmap combineImages(Bitmap background, Bitmap foreground, float disFromTheTopPercent) {
int width = background.getWidth(), height = background.getHeight();
Bitmap cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
background = Bitmap.createScaledBitmap(background, width, height, true);
comboImage.drawBitmap(background, 0, 0, null);
int top = (int) (disFromTheTopPercent * height);
int left = 0;
comboImage.drawBitmap(foreground, left, top, null);
return cs;
}
糟糕的是,它实际上与我的smartfon的身高、体重和dpi有关 当我将smartfone与5英寸屏幕和6英寸屏幕一起使用时,它是不同的,无论屏幕如何,它都必须看起来相同 谢谢你的帮助 请尝试以下代码:
public static Bitmap combineImages(Bitmap c, Bitmap s) {
Bitmap cs;
int width, height;
width = s.getWidth();
height = c.getHeight() + s.getHeight();
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, 0f, c.getHeight(), null);
return cs;
}