0

我试图弄清楚如何使用 Boost 库中的 GIL 在 C++ 中新创建的图像中定位图像。

#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
using namespace boost::gil;
int main()
{
    rgb8_image_t img(512, 512);
    rgb8_image_t img1;
    rgb8_image_t img2;
    png_read_image("img1.png", img1);//Code for loading an image
    png_read_image("img2.png", img2); //Code for loading 2nd image "img2.png" 
    //loading position of the images to an array or some kind of variable
    //passing in images and postions to the function to apply changes on newly created image with the  size of 512, 512 
    png_write_view("output.png", const_view(img)); //saving changes as "output.png"
}

我想做什么的图片

4

2 回答 2

2

您可以使用subimage_view来定位图像并copy_pixels复制它们。
您需要注意输入图像和输出子视图的大小是否匹配。如果它们不匹配,您也可以使用resize_view.
像这样的东西:

rgb8_image_t img1;
jpeg_read_image("img1.jpg", img1);
rgb8_image_t img2;
jpeg_read_image("img2.jpg", img2);

rgb8_image_t out_img(512, 512);
copy_pixels (view(img1), subimage_view(view(out_img), x, y, width, height));
copy_pixels (view(img2), subimage_view(view(out_img), x, y, width, height));
png_write_view("output.png", const_view(out_img));
于 2017-03-10T16:39:14.447 回答
0

如果有人好奇,这就是解决方案。

如何安装升压

如何安装 LibPng(加载 png 时需要)

#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_WARNINGS
#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
using namespace boost::gil;
int main()
{
    rgb8_image_t out_img(512, 512);
    rgb8_image_t img1;
    rgb8_image_t img2;
    png_read_image("img1.png", img1);//Code for loading img1
    png_read_image("img2.png", img2);//Code for loading img2
    copy_pixels(view(img1), subimage_view(view(out_img), 0, 0, 50, 50)); 
    copy_pixels(view(img2), subimage_view(view(out_img), 462, 462, 50, 50));
    png_write_view("output.png", const_view(out_img));

}

所有这些#define 都需要阻止 Visual Studio 显示错误。

顺便说一句,程序目录中必须有img1.png和img2.png,否则会出现内存错误。

于 2017-03-12T22:04:34.237 回答