TSDK_将启动icon加上渠道角标

在做打包自动化的过程中需要将有效的launcher加上渠道的角标如下所示:

ic_launcher.png

使用代码将合成过程自动化

public class MaskIcon {

private static String sourceName;

// sourcePath sourceName waterMarkFile
// c:/res/ ic_launcher.png xxhdpi.png
public static void main(String[] args) throws IOException {
    String sourcePath = args[0];
    sourceName = args[1];
    String waterMarkFile = args[2];
    
    File ldpiFile = new File(sourcePath + "drawable-ldpi-v4" + File.separator
            + sourceName);
    File mdpiFile = new File(sourcePath + "drawable-mdpi-v4" + File.separator
            + sourceName);
    File hdpiFile = new File(sourcePath + "drawable-hdpi-v4" + File.separator
            + sourceName);
    File xhdpiFile = new File(sourcePath + "drawable-xhdpi-v4" + File.separator
            + sourceName);
    File xxhdpiFile = new File(sourcePath + "drawable-xxhdpi-v4"
            + File.separator + sourceName);
    File waterMark = new File(waterMarkFile);
    if(ldpiFile.exists()) {
        mergeImage(ldpiFile, waterMark);
    }
    mergeImage(mdpiFile, waterMark);
    mergeImage(hdpiFile, waterMark);
    mergeImage(xhdpiFile, waterMark);
    mergeImage(xxhdpiFile, waterMark);
    
}

    public static void mergeImage(File source, File waterMark)
        throws IOException {
    BufferedImage biSource = ImageIO.read(source);

    int sourceWidth = biSource.getWidth();
    int sourceHeight = biSource.getHeight();

    BufferedImage biWaterMark = ImageIO.read(waterMark);

    // 将水印按照源图片大小缩放
    Image waterMarkSizeLikeSource = biWaterMark.getScaledInstance(
            sourceWidth, sourceHeight, 1);

    BufferedImage combined = new BufferedImage(sourceWidth, sourceHeight,
            BufferedImage.TYPE_INT_ARGB);

    Graphics g = combined.getGraphics();
    g.drawImage(biSource, 0, 0, sourceWidth, sourceHeight, null);
    g.drawImage(waterMarkSizeLikeSource, 0, 0, sourceWidth, sourceHeight,
            null);
    g.dispose();// 释放资源
    ImageIO.write(combined, "PNG", new File(source.getParent(), sourceName));
}
}
Paste_Image.png

如图所示传入三个参数, 源图片的路径,源图片名, 角标图片,生成图片效果如下

TSDK_将启动icon加上渠道角标_第1张图片
Paste_Image.png

Paste_Image.png

打包成 mask.jar 在windows 下面执行

win.png

Linux 下面执行

linux.png

你可能感兴趣的:(TSDK_将启动icon加上渠道角标)