1 Star 0 Fork 20

vigorlee/PythonUIAutomation4Windows

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bitmap_test.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
yinkaisheng 提交于 2016-11-10 09:23 . add class Bitmap
#!python3
# -*- coding: utf-8 -*-
import os
import time
import subprocess
import automation
def main():
width = 500
height = 500
cmdWindow = automation.GetConsoleWindow()
automation.Logger.WriteLine('create a transparent image')
bitmap = automation.Bitmap(width, height)
bitmap.ToFile('image_transparent.png')
cmdWindow.SetActive()
automation.Logger.WriteLine('create a blue image')
start = time.clock()
for x in range(width):
for y in range(height):
argb = 0x0000FF | ((255 * x // 500) << 24)
bitmap.SetPixelColor(x, y, argb)
cost = time.clock() - start
automation.Logger.WriteLine('write {}x{} image by SetPixelColor cost {:.3f}s'.format(width, height, cost))
bitmap.ToFile('image_blue.png')
start = time.clock()
for x in range(width):
for y in range(height):
bitmap.GetPixelColor(x, y)
cost = time.clock() - start
automation.Logger.WriteLine('read {}x{} image by GetPixelColor cost {:.3f}s'.format(width, height, cost))
start = time.clock()
argb = [(0xFF0000 | (0x0000FF * y // height) | ((255 * x // width) << 24)) for x in range(width) for y in range(height)]
bitmap.SetPixelColorsHorizontally(0, 0, argb)
cost = time.clock() - start
automation.Logger.WriteLine('write {}x{} image by SetPixelColorsHorizontally cost {:.3f}s'.format(width, height, cost))
bitmap.ToFile('image_red.png')
start = time.clock()
bitmap.GetAllPixelColors()
cost = time.clock() - start
automation.Logger.WriteLine('read {}x{} image by GetAllPixelColors cost {:.3f}s'.format(width, height, cost))
bitmap.ToFile('image_red.png')
bitmap.ToFile('image_red.jpg')
subprocess.Popen('image_red.png', shell = True)
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yanweilee/PythonUIAutomation4Windows.git
git@gitee.com:yanweilee/PythonUIAutomation4Windows.git
yanweilee
PythonUIAutomation4Windows
PythonUIAutomation4Windows
master

搜索帮助