Skip to content

Liang-Kaidong/show_bmp_to_lcd

Repository files navigation


libshow_bmp_to_lcd 静态库使用文档

版本: V1.0
作者: KD
日期: 2025-06-30


1. 功能概述

libshow_bmp_to_lcd.a 是一个针对 ARM Linux 平台的轻量级静态库,用于在 LCD 屏幕上显示 BMP 格式图片,支持以下特性:

  • ✅ 显示任意尺寸的 24 位色 BMP 图片
  • ✅ 指定显示位置(屏幕坐标)
  • ✅ 动态缩放图片到目标尺寸
  • ✅ 自动适配 LCD 屏幕分辨率

2. 快速开始

2.1 获取静态库

将以下文件放入项目目录:

  • libshow_bmp_to_lcd.a (静态库)
  • show_bmp_to_lcd.h (头文件)

2.2 基础调用示例

#include "show_bmp_to_lcd.h"

int main() {
    // 在屏幕坐标 (100, 50) 处显示图片,保持原始尺寸
    show_bmp_to_lcd("test.bmp", 100, 50, 0, 0);
    return 0;
}

2.3 编译命令

arm-linux-gnueabihf-gcc your_app.c -L. -lshowbmp -o app

3. API 接口说明

函数原型

void show_bmp_to_lcd(char *picname, int start_x, int start_y, int target_width, int target_height);

参数详解

参数 类型 说明
picname char* BMP 文件路径(如 "/images/test.bmp"
start_x int 图片左上角在屏幕的 X 坐标(单位:像素)
start_y int 图片左上角在屏幕的 Y 坐标(单位:像素)
target_width int 目标显示宽度(像素),设为 0 时使用图片原始宽度
target_height int 目标显示高度(像素),设为 0 时使用图片原始高度

返回值

  • 无显式返回值,失败时通过 perror 输出错误信息到标准错误流。

4. 完整示例代码

示例 1:居中显示图片

#include "show_bmp_to_lcd.h"
#include <stdio.h>

int main() {
    int screen_width = 800;  // 假设屏幕宽度为800
    int screen_height = 480; // 假设屏幕高度为480
    char *bmp_path = "logo.bmp";

    // 获取图片尺寸(需自行实现或预定义)
    int img_width = 320, img_height = 240; 

    // 计算居中坐标
    int start_x = (screen_width - img_width) / 2;
    int start_y = (screen_height - img_height) / 2;

    // 居中显示原始尺寸图片
    show_bmp_to_lcd(bmp_path, start_x, start_y, 0, 0);
    return 0;
}

示例 2:缩放图片到屏幕一半宽度

#include "show_bmp_to_lcd.h"

int main() {
    int screen_width = 800;
    char *bmp_path = "background.bmp";

    // 缩放到屏幕宽度的50%,高度等比例缩放
    show_bmp_to_lcd(bmp_path, 0, 0, screen_width / 2, 0);
    return 0;
}

5. 注意事项

  1. BMP 格式要求

    • 仅支持 24 位色无压缩 BMP 文件(位深度为 24,压缩方式为 0)。
    • 文件头必须符合 Windows BMP 标准(签名 "BM")。
  2. 系统依赖

    • 需 ARM Linux 环境,且已启用 Framebuffer 设备(/dev/fb0)。
    • 依赖系统调用:mmapioctlopen 等。
  3. 性能建议

    • 大尺寸图片缩放可能耗时,建议预处理图片尺寸。
    • 多次调用时复用已打开的 LCD 文件描述符可优化性能。
  4. 错误处理

    • 文件不存在时输出 "无法打开BMP文件"
    • 非法 BMP 格式时输出 "不是有效的BMP文件"

6. 附录

6.1 文件清单

文件 作用
libshow_bmp_to_lcd.a 静态库文件
show_bmp_to_lcd.h 函数声明和参数说明

6.2 技术支持

联系邮箱:226429965@qq.com


版权声明:使用时请保留作者信息,禁止用于商业闭源项目。


About

libshow_bmp_to_lcd.a是一个针对 ARM Linux 平台的轻量级静态库,用于在 LCD 屏幕上显示 BMP 格式图片.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages