我编写了一个从文件头读取图像宽度和高度的函数
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 字节中读取图像信息 从 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"));
// ...
}