You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何提升Streamlit中图片显示的清晰度?

解决Streamlit图片显示模糊、无法识别数字的问题
  • 先确认原图分辨率:如果图片本身分辨率不足,放大后必然模糊,优先替换为高清版本的原图。
  • 用PIL预处理图片并保留原始尺寸加载:
    通过PIL读取图片并转为RGB格式,同时指定原始宽度加载,避免Streamlit自动压缩:
    from PIL import Image
    import streamlit as st
    
    # 读取并转换为RGB
    img = Image.open("image.jpg").convert("RGB")
    # 按原始宽度显示,关闭自动列宽适配
    st.image(img, width=img.width, use_column_width=False)
    
  • 调整图片输出参数提升质量:
    在st.image中设置最高质量参数,或改用无压缩的PNG格式输出:
    # 针对JPG设置最高质量(范围0-100,默认75)
    st.image("image.jpg", quality=100)
    # 转为PNG无压缩格式输出
    st.image("image.jpg", output_format="PNG")
    
  • 清除Streamlit缓存并重启应用:本地运行时,点击页面右上角的"Clear cache"按钮,再重启应用,避免旧的压缩缓存影响显示。

内容的提问来源于stack exchange,提问作者Keerthi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 11:30:56