我正在尝试生成图像图标。基于一些限制,我需要按{r, g, b, a, r1, g1, b1, a1, ...}的顺序得到一个int32_t像素值的一维数组。在这种情况下,行的顺序应该与 OpenGL UV 相同(从下到上)。为此,我使用了以下,经过验证,它的工作原理:
const int image_width = image.width();
const int image_height = image.height();
if (!(image_width && image_height)) { return 1; }
int preview_width, preview_height;
if (image_width > image_height) {
preview_width = PREVIEW_SIZE;
preview_height = PREVIEW_SIZE * (float)image_height / (float)image_width;
}
else {
preview_width = PREVIEW_SIZE * (float)image_width / (float)image_height;
preview_height = PREVIEW_SIZE;
}
bg::rgba8_image_t preview_square(preview_width, preview_height);
const bg::rgba8_view_t& ps_viewer = bg::view(preview_square);
bg::resize_view(bg::const_view(image), ps_viewer, bg::bilinear_sampler());
std::vector<int32_t> arr(preview_width * preview_height);
memcpy(&arr[0], &ps_viewer[0], sizeof(int32_t) * arr.size());
根据 GIL 中像素的存储顺序,我需要沿 y 轴翻转图像。请告诉我如何实现这个?