2017-03-10 2 views
0

J'essaie de comprendre comment positionner une image dans une image nouvellement créée en C++ en utilisant la bibliothèque GIL de Boost.Positionnement d'une image dans une image à l'aide de GIL à partir de Boost en 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" 
} 

image of what i want to do

Répondre

1

Vous pouvez simplement utiliser la subimage_view pour positionner vos images et copy_pixels pour les copier.
Vous devez veiller à ce que les tailles des images d'entrée et de la sous-vue de sortie correspondent. Si elles ne correspondent pas, vous pouvez également utiliser le resize_view.
Quelque chose comme ça:

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)); 
0

Cette solution est si quelqu'un est curieux. sont nécessaires

How to install Boost

How to install LibPng (nécessaire pour le chargement .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)); 

}

Tous les #define pour arrêter visual studio d'apparaître des erreurs.

Btw dans le répertoire du programme, il doit y avoir img1.png et img2.png, sinon des erreurs de mémoire apparaîtront.