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

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")
相关推荐
希望20179 分钟前
Golang Panic & Throw & Map/Channel 并发笔记
开发语言·golang
朗迹 - 张伟10 分钟前
Golang安装笔记
开发语言·笔记·golang
yzx99101310 分钟前
生活在数字世界:一份人人都能看懂的网络安全生存指南
运维·开发语言·网络·人工智能·自动化
小周同学@31 分钟前
谈谈对this的理解
开发语言·前端·javascript
乔巴先生241 小时前
LLMCompiler:基于LangGraph的并行化Agent架构高效实现
人工智能·python·langchain·人机交互
橙*^O^*安2 小时前
Go 语言基础:变量与常量
运维·开发语言·后端·golang·kubernetes
NiKo_W2 小时前
Linux 文件系统与基础指令
linux·开发语言·指令
工程师小星星2 小时前
Golang语言的文件组织方式
开发语言·后端·golang
乂爻yiyao2 小时前
java 代理模式实现
java·开发语言·代理模式
张子夜 iiii2 小时前
实战项目-----Python+OpenCV 实现对视频的椒盐噪声注入与实时平滑还原”
开发语言·python·opencv·计算机视觉