我正在尝试将 .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);