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

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

Paste_Image.png

Paste_Image.png

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

win.png

Linux 下面执行

linux.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,290评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,288评论 19 139
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,835评论 4 61
  • 今天早上大概九点才起来吧,迷迷糊糊洗脸刷牙,然后把昨晚的数学作业继续抄完,没错,是抄,一个我在高中十分不屑的...
    摄心_阅读 1,715评论 3 1
  • 自己写原创的笑话是脱口秀演员的基本技能,所以首先学习的是如何写笑话。 在开始写笑话前,先要认识笑话的结构。 一个完...
    单口演员自白阅读 16,059评论 4 27

友情链接更多精彩内容