【发布时间】:2020-08-22 15:36:09
【问题描述】:
我写了一个从文件头读取图像宽度和高度的函数
int read_image_dimensions() {
namespace bg = boost::gil;
std::string filepath = "image.png";
std::ifstream byte_stream(filepath, std::ios::binary);
int width = 0, height = 0;
bg::image_read_info<bg::png_tag> png_tag_info;
png_tag_info = bg::read_image_info(byte_stream, bg::image_read_settings<bg::png_tag>())._info;
width = png_tag_info._width; height = png_tag_info._height;
std::cout << width << "x" << height << std::endl;
return 0;
}
而且我不知道如何从 python 字节中读取图像信息 Image data taken from Blender API,和写在图片文件里一样。
using namespace boost::python;
int read_image_dimensions(object &image) {
object image_packed_file = extract<object>(image.attr("packed_file"));
object packed_data = extract<object>(image_packed_file.attr("data"));
size_t packed_size = extract<size_t>(image_packed_file.attr("size"));
// ...
}
【问题讨论】:
-
我目前无法使用 bpy 设置工作 venv,但我想您可能可以解决我在这里给出的第二个示例:stackoverflow.com/a/61450277/85371
-
不幸的是,主要任务是使用python字节作为文件(那里的字节数据与磁盘上的图像完全相同,有一个已知的文件大小)。
-
但这是最简单的部分。如果你不介意我忽略所有 python 的东西,我会用这个来回答。
标签: boost boost-python boost-gil