【问题标题】:Android: Create image from two bitmaps, bitmap under bitmapAndroid:从两个位图创建图像,位图下的位图
【发布时间】:2019-03-20 11:21:14
【问题描述】:

我想要的:用两个位图创建图像,在第一个位图下放置第二个位图。


此时我使用此代码

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 相关联。

我用5寸和6寸的smartfone是不一样的,不管不同的屏幕,看起来都一样。

Visual presentation

感谢您的帮助!

【问题讨论】:

    标签: android bitmap android-bitmap android-image createbitmap


    【解决方案1】:

    试试这个代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多