我正在尝试将.hdr和.exr图像转换为调整大小的.png图像。转换部分按预期工作,但当我尝试在保存之前调整图像大小时,结果只是一张黑色图像。我使用的是github最新的OpenImageIO。
// read in an HDR or exr image
auto in = ImageInput::open (image_path.hdr);
const ImageSpec& spec = in->spec();
int w = spec.width;
int h = spec.height;
int channels = spec.nchannels;
// convert float to UNIT8
std::vector<unsigned char> pixels (w * h * channels);
in->read_image (TypeDesc::UINT8, pixels.data());
// resize and save to png format
ImageSpec s;
s.format = TypeDesc::UINT8;
s.width = w;
s.height = h;
s.nchannels = channels;
ImageBuf A (s, pixels.data());
// without resizing saving to .png works correctly
A.write(image_path.png);
// this results in an all black image
ROI roi (0, w/2, 0, h/2, 0, 1, 0,channels);
ImageBuf B;
ImageBufAlgo::resize (B, A, "", 0, roi);
B.write(image_path.png);发布于 2020-12-15 09:19:44
原来在调整大小时,ImageSpec字段full_width和full_height也需要填写。当它们存在时,调整大小的工作与预期的一样。
ImageSpec s;
s.format = TypeDesc::UINT8;
s.width = w;
s.height = h;
s.full_width = w;
s.full_height = h;https://stackoverflow.com/questions/65275912
复制相似问题