2017-03-10 15 views
0

Boost 라이브러리의 GIL을 사용하여 C++에서 새로 만든 이미지 내에 이미지를 배치하는 방법을 알아 내려고합니다.C++의 Boost에서 GIL을 사용하여 이미지 내에 이미지 위치 지정

#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

답변

1

당신은 당신의 이미지를 배치합니다 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)); 
0

이 솔루션입니다.

(PNG로드에 필요한)

How to install Boost

How to install LibPng

#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의 모든 오류를 표시하지 비주얼 스튜디오를 중지 할 필요가있다.

Btw 프로그램의 디렉토리에는 img1.png와 img2.png이 있어야합니다. 그렇지 않으면 메모리 오류가 표시됩니다.