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

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")
相关推荐
Jack N3 小时前
【Strapi 系列之五】前端怎么接?Next.js + Tailwind 拉取 Strapi 数据(含代码)
开发语言·前端·javascript·strapi
是Yu欸3 小时前
先让 T1 Pro 传回一张好用的图:JPEG 抓拍、RTSP 视频与方向校正
python·机器人·音视频
伞伞悦读3 小时前
【第60期】特征值不是重要性:Python 特征分解与 PCA 的前置判断
python
2601_967980113 小时前
Python之wxPython模块的安装
linux·windows·python·wxpython·gui设计·1024程序员节
云南新人和数采集团4 小时前
DeepSeek Harness 开源贡献手记:从入门到合入主线
python·开源·github
SuperHeroWu74 小时前
ArkGenie 的技术原理:从一段 SSE 到一个可交互 Surface
开发语言·php·交互
萝卜白菜。4 小时前
TongWeb生产环境配置规范之三:优化TongWeb启动速度
java·开发语言
企业解惑小助手4 小时前
上网行为监控软件有哪些?部署后终端卡顿、断网、审计缺失怎么办?一份完整故障排查手册
开发语言·php
信誓旦旦的程序猿4 小时前
【Python量化实战宝典 #20】动量、反转择时手册:趋势跟随与均值回归(Python 可跑)
java·python·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口