准备工作:
1.一部Android手机 文中测试机型为三星S8.
2.一个Python3.*环境.
3.安装好adb测试桥.
测试环境:macOS 10.13.2* Python3.6
import os
import pygame,tqdm
def StringList(text,size):
pygame.init()
font = pygame.font.Font(os.path.join("/System/Library/Fonts", "STHeiti Light.ttc"), size)
#字体文件存放位置,本实例为macOS字体位置,windows请另找路径
rtext = font.render(text, True, (0, 0, 0), (255, 255, 255))
rtext = pygame.transform.flip(rtext, True, False)
rtext = pygame.transform.rotate(rtext, 90)
#rtext为pygame的surface对象
ImageList = []
pygame.image.save(rtext, "t.jpg")
#将surface对象转换成二维矩阵数组
for x in range(0, rtext.get_height()):
FirstList = []
for y in range(0, rtext.get_width()):
FirstList.append(rtext.get_at((y, x))[0])
ImageList.append(FirstList)
return ImageList
def PrintString(size=1400,string='帅',left=0,top=450):
ImageList = StringList(string, size) # 一个字符1400大小两个700大小
llll = []
tryt = 0
for x in range(0, len(ImageList)):
for y in range(0, len(ImageList[x])):
t = ''
if ImageList[x][y] < 10:
if tryt != 0:
tryt = tryt - 1
else:
while 1 == 1:
if ImageList[x][y + tryt] < 10:
tryt = tryt + 1
ft = False
else:
llll.append(([[x], [y], [y + tryt]]))
break
rr = 0
density = 30
# 作画密度参数
for xx in tqdm.tqdm(range(0, len(llll))):
try:
if llll[xx][0] != llll[xx - 1][0]:
rr = rr + 1
except:
print('over')
if rr % density == 0:
os.system(
'adb shell input swipe ' + str(llll[xx][0][0] +left) + ' ' + str(llll[xx][1][0] + top) + ' ' + str(
llll[xx][0][0] +left) + ' ' + str(llll[xx][2][0] + top))
if __name__ == '__main__':
PrintString(size=1400,string='帅',left=0,top=450)
测试效果: