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

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")
相关推荐
Doc.S1 天前
【保姆级教程】在AutoDL容器中部署EGO-Planner,实现无人机动态避障规划
人工智能·python·信息可视化·机器人
骚戴1 天前
PDF或Word转图片(多线程+aspose+函数式接口)
java·开发语言
姓蔡小朋友1 天前
SpringDataRedis
java·开发语言·redis
Predestination王瀞潞1 天前
Python3:Eighth 函数
开发语言·python
蒋星熠1 天前
多模态技术深度探索:融合视觉与语言的AI新范式
人工智能·python·深度学习·机器学习·分类·数据挖掘·多分类
夜晚中的人海1 天前
【C++】分治-快速排序算法习题
开发语言·c++·排序算法
xier_ran1 天前
Python从入门到精通:(2)Python 核心进阶教程从数据结构到面向对象
linux·windows·python·microsoft
爱编程的鱼1 天前
想学编程作为今后的工作技能,学哪种语言适用性更强?
开发语言·算法·c#·bug
yugi9878381 天前
基于MATLAB的心电信号去噪
开发语言·matlab
国服第二切图仔1 天前
Rust入门开发之Rust中如何实现面向对象编程
开发语言·后端·rust