麒麟系统播放图片 速度比较

pygame效果比opencv好,opencv有锯齿:

python 复制代码
import pygame
import os
import time

def show_image_sdl(image_path):
    """使用SDL2快速显示图片"""
    # 初始化pygame
    pygame.init()
    
    # 获取屏幕信息
    info = pygame.display.Info()
    screen_width, screen_height = info.current_w, info.current_h
    
    # 创建全屏窗口
    screen = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
    pygame.display.set_caption("快速图片查看器")
    pygame.mouse.set_visible(False)  # 隐藏鼠标
    
    # 加载图片
    try:
        # 直接加载并转换格式以加速显示
        image = pygame.image.load(image_path).convert()
        
        # 计算缩放比例(屏幕两倍大小)
        img_width, img_height = image.get_size()
        scale_x = (screen_width * 1) / img_width
        scale_y = (screen_height * 1) / img_height
        scale_factor = min(scale_x, scale_y)
        
        # 缩放图片
        new_width = int(img_width * scale_factor)
        new_height = int(img_height * scale_factor)
        scaled_image = pygame.transform.smoothscale(image, (new_width, new_height))
        
        # 计算居中位置
        x_pos = (screen_width - new_width) // 2
        y_pos = (screen_height - new_height) // 2
        
        # 显示图片
        screen.blit(scaled_image, (x_pos, y_pos))
        pygame.display.flip()
        
        print(f"图片显示完成: {new_width}x{new_height}")
        
        # 等待退出
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT or \
                   (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                    running = False
            time.sleep(0.01)  # 减少CPU占用
            
    except Exception as e:
        print(f"错误: {e}")
    
    finally:
        pygame.quit()

# 使用
if __name__ == "__main__":
    show_image_sdl("/home/yklele/hongmeng_s.jpg")
相关推荐
多米Domi01139 分钟前
0x3f 第49天 面向实习的八股背诵第六天 过了一遍JVM的知识点,看了相关视频讲解JVM内存,垃圾清理,买了plus,稍微看了点确定一下方向
jvm·数据结构·python·算法·leetcode
饺子大魔王的男人40 分钟前
Remote JVM Debug+cpolar 让 Java 远程调试超丝滑
java·开发语言·jvm
人工智能训练6 小时前
【极速部署】Ubuntu24.04+CUDA13.0 玩转 VLLM 0.15.0:预编译 Wheel 包 GPU 版安装全攻略
运维·前端·人工智能·python·ai编程·cuda·vllm
yaoming1686 小时前
python性能优化方案研究
python·性能优化
兩尛7 小时前
c++知识点2
开发语言·c++
fengfuyao9857 小时前
海浪PM谱及波形的Matlab仿真实现
开发语言·matlab
xiaoye-duck7 小时前
C++ string 底层原理深度解析 + 模拟实现(下)——面试 / 开发都适用
开发语言·c++·stl
码云数智-大飞7 小时前
使用 Python 高效提取 PDF 中的表格数据并导出为 TXT 或 Excel
python
Hx_Ma168 小时前
SpringMVC框架提供的转发和重定向
java·开发语言·servlet
biuyyyxxx8 小时前
Python自动化办公学习笔记(一) 工具安装&教程
笔记·python·学习·自动化