0

I have an image loaded from a file like this:

string FILE_IN = "file.cimg;
CImg<float> image_small;
CImg<float> image_big;
image.load_cimg(file_in);

And I want to copy-paste the exact image in image_small to image_big, but specifying the position (coordinates) where to do it.

I have looked at the functions in the library, but I only find assign() or get_shared(), which don't accept this options.

Anthony
  • 443
  • 1
  • 5
  • 16
  • 1
    Do you mean, like [draw_image](http://cimg.sourceforge.net/reference/structcimg__library_1_1CImg.html#a952f376650e7aed047648391a55da5de)? – Roger Rowland Nov 19 '13 at 12:54
  • Thanks @RogerRowland! but I am trying `image_big.draw_image(0, 0, image_small, 1);`, and at that line the program fails with a SEGMENTATION FAULT error. any idea why? – Anthony Nov 19 '13 at 13:53
  • I've no idea why - I don't have your source code or your knowledge about the problem domain. I could guess that `image_small` is perhaps bigger in at least one dimension than `image_big` but you'll need to get back to normal debugging now - I just pointed you at a suitable function. – Roger Rowland Nov 19 '13 at 14:03

1 Answers1

1

Working code:

#include <iostream>

#define cimg_display 0
#define cimg_use_jpeg 1

#include "CImg.h"

int main() {

    using namespace std;
    using namespace cimg_library;

    CImg<unsigned char> *bigImage = new CImg<unsigned char>("lena.jpg");
    CImg<unsigned char> *smallImage = new CImg<unsigned char>("lena.jpg");
    //x - coordinate, y - coordinate, overlay image, opacity
    bigImage->draw_image(50, 50, 0, *smallImage, 100);
    bigImage->save("lenaNew.jpg");
    return 0;
}

Image source https://jviolajones.googlecode.com/files/lena.jpg

Nazar Sakharenko
  • 1,007
  • 6
  • 11