博客
关于我
Android笔记---framebuffer 显示图像文件(QImage方式)
阅读量:788 次
发布时间:2019-03-24

本文共 843 字,大约阅读时间需要 2 分钟。

近期,我在进行AndroidFramebuffer显示16位深度图片的研究,经历了无数个痛苦的→逐步分析如下:

  • 初始化Frame Buffer:首先,我需要访问Android系统中的Framebuffer设备,路径如"/dev/graphics/fb1"。使用C语言的open函数进行读写,这需要root权限。

  • 加载图片:使用Qt的QImage类加载图片,指定源路径。通过qimage.load(imagePath),我可以获得图片的像素数据。需要注意的是,QImage的像素数据格式默认是ARGB8888,顺序是B, G, R,需注意数据排列方向。

  • 转换格式:Frame Buffer主要支持RGB565格式,与16位颜色相符。因此,我需要将QImage的ARGB8888转换为RGB565。具体步骤是:

    • 遍历像素数据,将每个四字节拆分为R、G、B三个分量。
    • 计算每个RGB565编码值:(G >> 3) | (B << 3), (R & 0xF8) | (G >> 5)。
  • 显示到Frame Buffer:使用mmap函数将Frame Buffer的内存区域进行映射,便于直接进行内存操作。然后,通过 memcpy将转换后的像素数据填充至相应位置,注意位移和顺序。

  • 测试与验证

    • 使用颜色常量定义,如RGB565 colormap,测试基础颜色是否正确显示。
    • 输出调试信息,检查图像数据是否读取和转换正确。
  • 优化与解决问题

    • 初次尝试直接写入像素数据发现颜色偏差,需检查QImage的读取方式是否正确。
    • 遇到jpeglib库集成问题,通过交叉编译和路径配置得以解决。
    • 变通方法使用QImage处理后,再次成功将图片显示到Frame Buffer,完成目标。
  • 总结:通过Qt的便捷API和自定义转换逻辑,我最终实现了在16位Frame Buffer上显示高质量图片的能力。这一过程涉猎了Framebuffer内存管理、像素格式转换、软件编程接口应用等多个技术点,提升了嵌入式开发能力。

    转载地址:http://jxokk.baihongyu.com/

    你可能感兴趣的文章
    ThreadLocal线程内部存储类
    查看>>
    thinkphp 常用SQL执行语句总结
    查看>>
    Oracle:ORA-00911: 无效字符
    查看>>
    Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
    查看>>
    TCP基本入门-简单认识一下什么是TCP
    查看>>
    tableviewcell 中使用autolayout自适应高度
    查看>>
    Orcale表被锁
    查看>>
    svn访问报错500
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    SQL-CLR 类型映射 (LINQ to SQL)
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>