android开机动画包制作工具实现「建议收藏」

android开机动画包制作工具实现「建议收藏」android开机动画包制作  由于项目的需要,要制作LOGO有光亮的闪烁,网上查了资料,都是介绍 desc.txt文件的格式,但对于每一帧的图片制作没有现成的工具,所以本人试着自己先一个,只要满足自己的需求(logo光来回扫动)就行,其他复杂的情况不考虑。  首先是 desc.txt的实现:  102460016  p00part0  很简单,分辨率,播

大家好,又见面了,我是你们的朋友全栈君。

android开机动画包制作

   由于项目的需要,要制作LOGO有光亮的闪烁,网上查了资料,都是介绍 desc.txt 文件的格式,但对于每一帧的图片制作没有现成的工具,所以本人试着自己先一个,只要满足自己的需求(logo光来回扫动)就行,其他复杂的情况不考虑。
   首先是 desc.txt 的实现:
  1024 600 16
   p 0 0 part0
   很简单,分辨率,播放帧率都有软件自动生成,分辨率根据logo的大小来设定。

   接着,就是怎么实现每一帧图片了,首先,叫美工画了3张图,一张logo,一张光,还有一张掩膜,举个例子
   logo图片:
android开机动画包制作工具实现「建议收藏」

光:
android开机动画包制作工具实现「建议收藏」

掩膜:
android开机动画包制作工具实现「建议收藏」


先让 logo图片和光做alpha运算,得到一张黑色底图都带光的图片:
android开机动画包制作工具实现「建议收藏」


为了去掉黑色区域的白光,所以最后与掩膜做alpha叠加,变为:
android开机动画包制作工具实现「建议收藏」


原理基本就这样,然后光从左到右移动,生成一张张图片,
我是用Python写的,看源码吧:
# coding=utf-8
__author__ = 'snomy'


import os
import shutil
import Image
import ImageFilter
import zipfile
import sys


# ---------------------- 函数 --------------------------
def isFullBlack(xy, image):
    point_cnt = 0
    xy_left = (xy[0]-1, xy[1]+0)
    xy_right = (xy[0]+1, xy[1]+0)
    xy_up = (xy[0]+0, xy[1]-1)
    xy_bottom = (xy[0]+0, xy[1]+1)


    lst = [xy, xy_left, xy_right, xy_up, xy_bottom]
    for i in lst:
        xxx = i[0]
        yyy = i[1]
        if i[0] < 0:
            xxx = 0
        if i[0] >= image.size[0]:
            xxx =  xy[0]
        if i[1] < 0:
            yyy = 0
        if i[1] >= image.size[1]:
            yyy = xy[1]


        if image.getpixel((xxx, yyy)) != (0, 0, 0, 255):
            point_cnt += 1
    return point_cnt


# ---------------------- 程序执行 --------------------------
# 步进多少像数分割图片
MOVE_PIX = 32


# 判断logo.png是否存在,不存在退出
if not os.path.exists("logo.png"):
    print "logo.png is not existent"
    sys.exit()


# 判断guang.png是否存在,不存在退出
if not os.path.exists("guang.png"):
    print "guang.png is not existent"
    sys.exit()


# 1. 输入每秒显示几张
if len(sys.argv) >= 2:
    pics_per_second = eval(sys.argv[1])
    if pics_per_second <= 0:
        print "too small"
        sys.exit()
    if pics_per_second > 60:
        print "too large"
        sys.exit()
    if 1<= pics_per_second <= 60:
        print pics_per_second, "frame/s"
else:
    while True:
        pics_per_second = input("frame/s: ")
        if pics_per_second <= 0:
            print "too small"
        if pics_per_second > 60:
            print "too large"
        if 1<= pics_per_second <= 60:
            break


Im = Image.open("logo.png")
print "logo.png"
print Im.mode, Im.size, Im.format


Im_guang = Image.open("guang.png")
print "guang.png"
print Im_guang.mode, Im_guang.size, Im_guang.format


# 先删除文件夹
if os.path.exists("part0"):
    shutil.rmtree("part0")
# 创建文件夹
os.mkdir("part0")


# 判断文件是否存在
if os.path.exists("desc.txt"):
    os.remove("desc.txt")


# 2. 生成 desc.txt 文件
hDescFile = open("desc.txt", mode='w')
hDescFile.write("%d %d %d\n" % (Im.size[0], Im.size[1], pics_per_second))
hDescFile.write("p 0 0 part0\n")
hDescFile.close()


# 2.5 判断是否存在掩膜图片,没有则生成掩膜图片,有则使用现有的
img_mask = Image.new('RGBA', Im.size)
if not os.path.exists("mask.png"):
    print "mask.png is not existent"
    img_mask.paste(Im, (0, 0))
    for height in range(img_mask.size[1]):
        for width in range(img_mask.size[0]):
            #if img_mask.getpixel((width, height)) != (0, 0, 0, 255):
            cnt = isFullBlack((width, height), Im)
            if cnt == 5:
                img_mask.putpixel((width, height), ((0, 0, 0, 0)))
            elif cnt == 4:
                img_mask.putpixel((width, height), ((0, 0, 0, 50)))
            elif cnt == 3:
                img_mask.putpixel((width, height), ((0, 0, 0, 100)))
            elif cnt == 2:
                img_mask.putpixel((width, height), ((0, 0, 0, 150)))
            elif cnt == 1:
                img_mask.putpixel((width, height), ((0, 0, 0, 200)))
    #img_mask.save("img_mask.png")
else:
    print "use mask.png"
    img_mask = Image.open("mask.png")
    print img_mask.mode, img_mask.size, img_mask.format


# 3. 生成 每张图片
index = 0
while True:
    if MOVE_PIX*index > Im.size[0]:
        break
    new_img = Image.new('RGB', Im.size)
    new_img.paste(Im, (0, 0))
    new_img.paste(Im_guang, (MOVE_PIX*index, 0), Im_guang)
    new_img.paste(img_mask, (0, 0), img_mask)
    save_path = "part0/%04d.png" % index
    print save_path
    new_img.save(save_path, "PNG")
    index += 1
#end while


# 4. 生成zip文件
if os.path.exists("bootanimation.zip"):
    os.remove("bootanimation.zip")


zpfd = zipfile.ZipFile("bootanimation.zip", mode='w', compression=zipfile.ZIP_STORED)
zpfd.write("desc.txt")
startdir = "part0"
for dirpath, dirnames, filenames in os.walk(startdir):
    for filename in filenames:
        zpfd.write(os.path.join(dirpath, filename))
zpfd.close()
print " -------- make bootanimation.zip OK --------"


# 5. 清理文件
if os.path.exists("part0"):
    shutil.rmtree("part0")


if os.path.exists("desc.txt"):
    os.remove("desc.txt")
OK,完成了,工具已上传,大家有需要的可以去下
http://download.csdn.net/detail/snomy/9538784


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146720.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MFC 消息处理 PeekMessage TranslateMessage DispatchMessage

    MFC 消息处理 PeekMessage TranslateMessage DispatchMessagehttp blog csdn net linlingzhao article details 由 arain 于星期二 11 02 2010 10 44 发表 MSGmessage nbsp nbsp if PeekMessage amp message NULL 0 0 PM REMOVE nbsp nbsp nbsp nbsp nbsp nbsp TranslateMes amp m

    2025年11月1日
    5
  • 《STM32固件库使用手册》_mate20x刷回出厂版本

    《STM32固件库使用手册》_mate20x刷回出厂版本最近领导让我学学嵌入式开发,在网上看了看老前辈们总结的嵌入式开发学习不归路,还是决定按照步骤开始学习。首先是获取到《STM32固件库使用手册》和《STM32F10x参考手册》两个开局手册,在网上找了找资源,发现居然还要收费下载!明明STM官网就能免费下载(笑哭)做人厚道一点啊~下载地址:固件库使用手册链接:https://pan.baidu.com/s/1n_flJ3TuGo4Nvf3dMOKOKg提取码:qrb2参考手册链接:https://pan.baidu.com/s/1beJlqU

    2022年8月31日
    3
  • dpkg说明_dpkg命令

    dpkg说明_dpkg命令dpkg与centos中的rpm相似,被用于安装,卸载及查询deb包信息。下面简单介绍基础命令。已有安装包:test.deb。安装命令:dpkg-itest.deb安装test.deb软件包dpkg-ctest.deb#查看test.deb软件包中包含的文件结构安装后查询命令:dpkg-Itest查看已安装的test.deb软件包的详细信息,包括软件名称、版本等dpkg-Ltest#查看已安装test.deb软件包安装的所有文件dpkg-stest#查看test.

    2022年10月7日
    3
  • 关于mysql的时区(下):如何设置mysql的时区

    关于mysql的时区(下):如何设置mysql的时区一、如何设置mysql时区1、命令1)查时区:showvariableslike’%time_zone%’返回有2行记录,要看time_zone变量的值,不需要看system_time_zone。若值为SYSTEM表示取值跟system_time_zone保持一致。system_time_zone的值是启动mysql服务的时候读取了操作系统的值,除非重新启动mysql服务重读否则这个值不变2)设置会话时区:settime_zone=’+8:00’仅对当前会话有效,在当前窗口立即生效

    2025年6月15日
    3
  • idea2021.3 激活码(JetBrains全家桶)

    (idea2021.3 激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html1STL5S9V8F-eyJsaWNlbnNlSW…

    2022年3月27日
    598
  • Linux -bash: redis-cli: command not found(亲测可行)

    Linux -bash: redis-cli: command not found(亲测可行)

    2022年2月8日
    57

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号