2017-10-04 130 views
0

我想在另一个窗口上显示一个图像,但在同一个窗口中。我看过帖子并肩作战,但我已经知道如何做到这一点。这里是我到目前为止有:如何使用CImg.h库在另一个图像上显示一个图像?

string firstFile = ""; 
string secondFile = ""; 
cout << "Enter the filenames corresponding to the Image and the Logo (in that order): " << endl; 
cin >> firstFile; 
cin >> secondFile; 

const char* filename = firstFile.c_str(); 
CImg<unsigned char> img1(filename); 

const char* filename2 = secondFile.c_str(); 
CImg<unsigned char> img2(filename2); 

int w = img1.width(); 
int h = img1.height(); 
int channels = img1.spectrum(); 

cout << "Successfully loaded image " << firstFile << " of size " << w << " x " << h << " x " << channels << endl; 

int w2 = img2.width(); 
int h2 = img2.height(); 
channels = img2.spectrum(); 
cout << "Successfully loaded image " << secondFile << " of size " << w2 << " x " << h2 << " x " << channels << endl; 

cout << "Enter the position in (x, y) coordinates where this logo must be placed." << endl << "x must be between 0 and 239 and y must be between 0 and 191." << endl; 
int x1, y1; 
cin >> x1; 
cin >> y1; 

char title[100]; 
sprintf(title, "%s (%d x %d x %d)", filename, w, h, channels); 


CImgDisplay disp(img1, title, 0); 
img1.display(disp, false); 

回答

0

像这样:

// Draw img2 on top of img1 at (x1,y1) 
    img1.draw_image(x1,y1,img2); 
+0

谢谢!只需要注意可能存在问题的其他人,我必须在显示img1之前发表声明。 –

相关问题