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

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")
相关推荐
爱笑的眼睛1111 分钟前
深入解析Matplotlib Axes API:构建复杂可视化架构的核心
java·人工智能·python·ai
爱埋珊瑚海~~12 分钟前
基于MediaCrawler爬取热点视频
大数据·python
工程师丶佛爷14 分钟前
从零到一MCP集成:让模型实现从“想法”到“实践”的跃迁
大数据·人工智能·python
刺客xs22 分钟前
Qt------信号槽,属性,对象树
开发语言·qt·命令模式
2501_9216494924 分钟前
免费获取股票历史行情与分时K线数据 API
开发语言·后端·python·金融·数据分析
尤物程序猿29 分钟前
Java如何不建表完成各种复杂的映射关系(鉴权概念、区域概念、通用概念)
java·开发语言
高洁011 小时前
DNN案例一步步构建深层神经网络(二)
人工智能·python·深度学习·算法·机器学习
Insight.1 小时前
背包问题——01背包、完全背包、多重背包、分组背包(Python)
开发语言·python
aini_lovee1 小时前
改进遗传算法求解VRP问题时的局部搜索能力
开发语言·算法·matlab
Lucky高1 小时前
Pandas库实践1_预备知识准备
python·pandas