下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!/usr/bin/env python# -*- Coding: utf-8 -*-##-------------------------------------------------------------------------------# name: 解析天气数据类## Author: Small White## Created: 2014-09-09## Python Tested: 3.4.1## dependency:# 1) Pillow# 2) pywin32 (e.g. Python for windows)# 3) win32-py3.4## Modification History:#-------------------------------------------------------------------------------from PIL import Image,ImageDraw,ImageEnhanceimport win32gui,win32con,win32APIimport osfrom WeatherReport34 import WeatherReportCWD = os.path.split(os.path.realpath(__file__))[0]def reduceOpacity(image,opacity): """Returns an image with reduced opacity.""" assert opacity >= 0 and opacity <= 1 if image.mode != 'RGBA': image = image.convert('RGBA') Alpha = image.split()[3] Alpha = ImageEnhance.Brightness(Alpha).enhance(opacity) image.putAlpha(Alpha) return imagedef adDWatermark(image,watermark,position,opacity=1): """Adds a adDWatermark to an image.""" if opacity < 1: watermark = reduceOpacity(watermark,opacity) if image.mode != 'RGBA': image = image.convert('RGBA') # create a transparent layer the size of the image and draw the # watermark in that layer. layer = Image.new('RGBA',image.size,(0,0)) if position == 'tile': for y in range(0,image.size[1],watermark.size[1]): for x in range(0,image.size[0],watermark.size[0]): layer.paste(watermark,(x,y)) elif position == 'scale': # scale,but preserve the aspect ratio ratio = min( float(image.size[0]) / watermark.size[0],float(image.size[1]) / watermark.size[1]) w = int(watermark.size[0] * ratio) h = int(watermark.size[1] * ratio) watermark = watermark.resize((w,h)) layer.paste(watermark,((image.size[0] - w) / 2,(image.size[1] - h) / 2)) else: layer.paste(watermark,position) # composite the watermark with the layer return Image.composite(layer,image,layer) def setWallpaperFromBMP(imagepath,paperStyle = "TILE"): """ Chage desktop background using the picture from the imagepath """ # 平铺 (默认) styleSetting = "1" tileSetting = "1" if paperStyle == "CENTER":# 0桌面居中 styleSetting = "0" tileSetting = "0" elif paperStyle == "STRETCH":# 2拉伸适应桌面 styleSetting = "2" tileSetting = "0" k = win32API.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\Desktop",win32con.KEY_SET_VALUE) win32API.RegSetValueEx(k,"WallpaperStyle",win32con.REG_SZ,styleSetting) win32API.RegSetValueEx(k,"TileWallpaper",tileSetting) win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,imagepath,1+2)def hasCrosslineBetweenBoxes(Box1,Box2): return abs((Box1[0]+Box1[2])/2.0 - (Box2[0]+Box2[2])/2.0) <= ((Box1[2]+Box2[2]-Box1[0]-Box2[0])/2.0) and \ abs((Box1[1]+Box1[3])/2.0 - (Box2[1]+Box2[3])/2.0) <= ((Box1[3]+Box2[3]-Box1[1]-Box2[1])/2.0)if __name__ == "__main__": screenWIDth = vscreenwIDth = win32API.GetSystemMetrics(win32con.SM_cxvIRTUALSCREEN) screenHeight = vscreenheigth = win32API.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN) vscreenx = win32API.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN) vscreeny = win32API.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN) ''' Returns only one monitor size,so we don't use them. screenWIDth = win32API.GetSystemMetrics(win32con.SM_CXSCREEN) screenHeight = win32API.GetSystemMetrics(win32con.SM_CYSCREEN) ''' bgImage = Image.new('RGBA',(screenWIDth,screenHeight),color = 0) bgImageDraw = ImageDraw.ImageDraw(bgImage) weatherReport = WeatherReport() weatherReportimage = weatherReport.getWeatherReportimage() bgImage = adDWatermark(bgImage,weatherReportimage,(15,15),1) weatherReportimage.close() if bgImage.mode != 'RGB': R,G,B,A = bgImage.split() bgImage = Image.merge("RGB",(R,B)) bgImage.save(CWD + os.sep + "backgroud.bmp","BMP") setWallpaperFromBMP(CWD + os.sep + "backgroud.bmp") bgImage.close()
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的将天气情况设置为桌面壁纸全部内容,希望文章能够帮你解决将天气情况设置为桌面壁纸所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)