gpt4 book ai didi

c - stbi_load_from_memory 没有正确读取图像尺寸

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:55 31 4
gpt4 key购买 nike

我正在使用 ld -r -b binary -o res.o * 将一个包含多个 png 图像的文件夹嵌入到我的 C 程序中,其中一个名为 font .png.

在我的代码中,我使用这段代码加载带有 stb_image 的嵌入式 font.png:

char* img;
int w, h, n;
extern char* _binary_font_png_start;
extern char* _binary_font_png_end;
img = (char*)stbi_load_from_memory((unsigned char*)_binary_font_png_start, _binary_font_png_end - _binary_font_png_start, &w, &h, &n, 4);

实际图像尺寸为 256x128,但 stbi 给出的 w(宽度)值为 0,h(高度)值为 2293200。出了什么问题?

最佳答案

最终通过如下更改我的代码使其工作:

char* img;
int w, h, n;
extern char _binary_font_png_start, _binary_font_png_end;
img = (char*)stbi_load_from_memory((unsigned char*)&_binary_font_png_start, &_binary_font_png_end - &_binary_font_png_start, &w, &h, &n, 4);

有点奇怪,但它有效,所以我猜它是正确的?无法找到有关将这些符号链接(symbolic link)到 c 代码的“预期”方式的任何文档,但它们似乎代表二进制数据末尾/开头的字符,而不是指向该字符的指针,因为我意料之中。

关于c - stbi_load_from_memory 没有正确读取图像尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44791146/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com