赞
踩
- res/
- drawable/
- a.png
- drawable-ldrtl/
- a.png // 对标 drawable/a.png 的 RTL 图标
- drawable-xhdpi/
- b.png
- drawable-ldrtl-xhdpi/
- b.png // 对标 drawable-xhdpi/b.png 的 RTL 图标
有了这个知识以后。
我们就知道 只需要将项目里面的 带left_xx_.png 的图 复制旋转。并且替换到新的目录 那么就完成了
主要针对左右箭头。。很显眼
- import os
- from PIL import Image
-
-
- def main():
- # 遍历所有的目录找出带左右文件的png
- for root, dirs, files in os.walk("/Users/liuan/AndroidStudioProjects/haive/haive-android"):
- for file in files:
- if (file.endswith(".png") and file.__contains__("right")) or (
- file.__contains__("left") and file.endswith(".png")):
- # # 获取文件名
- name = file.split(".")[0]
- # # 获取文件的路径
- path = os.path.join(root, file)
-
- # 已有ldrtl 则无需再次进行拼接
- if path.__contains__("ldrtl"):
- continue
- # 临时文件目录无需进行替换
- if path.__contains__("/build/intermediates"):
- continue
-
- parentPath = path.split("/")[-2]
-
- # drawable-xxhdpi 中间插入 -ldrtl
- # "-"前面插入数据
-
- newList = []
- index = 0
-
- for x in parentPath.split("-"):
- if index == 1:
- newList.append("ldrtl")
- newList.append(x)
- index = index + 1
- # 将数组转换成字符串由"-"连接
- newParentPath = "-".join(newList)
- newFilePath = path.replace(parentPath, newParentPath)
-
- # 判断newFilePath 父目录是否存在 不存在则创建
- if not os.path.exists(os.path.dirname(newFilePath)):
- os.makedirs(os.path.dirname(newFilePath))
-
- if not os.path.exists(newFilePath):
- # 图片旋转180度并保存为新的路径
- print("以下文件将会被替换##########################")
- print(name)
- print(path)
- print(newFilePath)
- im = Image.open(path)
- im = im.rotate(180)
- im.save(newFilePath)
-
-
- if __name__ == '__main__':
- main()

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。