编程语言
首页 > 编程语言> > 使用python获取win10锁屏照片

使用python获取win10锁屏照片

作者:互联网

环境:

windows10

python 3.7

Pillow库

使用 pip install Pillow 安装

1. 先在文件浏览器中输入 %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets 然后拷贝实际地址,替换python中 TARGET_PATH 对应部分;

2. 把下面的python代码脚本和批处理脚本放在同一个目录下,双击批处理就可以看到锁屏照片;

3. python程序中通过 MIN_IMAGE_W 和 MIN_IMAGE_H 来设定最小的图片分辨率,可根据实际情况修改;

python 源码:

add_extend.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
__author__ = 'ppdyhappy'

import os
import shutil
from PIL import Image


TARGET_PATH = r'use your own file path here!'
MIN_FILE_SIZE = 300*1024
MIN_IMAGE_W = 1920
MIN_IMAGE_H = 1080


def do_add_extend(path, cur_file_name_list):

    for _, _, filenameArr in os.walk(TARGET_PATH):
        for name in filenameArr:
            file_path = os.path.join(TARGET_PATH, name)
            if os.path.getsize(file_path) <= MIN_FILE_SIZE:
                continue

            if name + '.jpg' in cur_file_name_list:
                continue

            w, h = Image.open(file_path).size
            if w < MIN_IMAGE_W or h < MIN_IMAGE_H:
                continue

            new_file_path = os.path.join(path, name + '.jpg')
            shutil.copy(file_path, new_file_path)


def get_cur_jpg_file_list(path):

    temp_list = []

    for _, _, filenameArr in os.walk(path):
        for name in filenameArr:
            if name.endswith('.jpg'):
                # print(name)
                temp_list.append(name)

    return temp_list


def add_extend():
    cur_path = os.getcwd()

    cur_jpg_file_list = get_cur_jpg_file_list(cur_path)

    do_add_extend(cur_path, cur_jpg_file_list)


if __name__ == '__main__':
    add_extend()
    print('Done')

批处理内容:

python ./add_extend.py

效果:

 

标签:TARGET,MIN,python,锁屏,file,win10,path,os
来源: https://blog.csdn.net/ppdyhappy/article/details/120777403