在 C++ 上使用 CImg class 显示多个图像
Display several images using CImg class on C++
如何将多张卡片(52 张卡片)图像显示到一张 'grid' 中?
我正在尝试在左上角创建四个桩,在右上角创建四个桩,使用 CImg
class 构成我游戏的主要 table 的八个桩.
CImg本身就有非常基本的显示图像的能力windows。您所能做的就是显示多个图像,使用 CImgDisplay 结构将它们沿其中一个轴对齐。请参阅 CImgDisplay::display() method 的文档。您可以尝试使用 4 个可用轴,看看它是否符合您的需求。
如果这对你来说还不够,你必须使用一些外部库来显示。
更新答案
您可以这样使用 append()
:
#include "CImg.h"
using namespace cimg_library;
int main() {
// Load up all images into CImg structures
CImg<unsigned char> c7("7.png");
CImg<unsigned char> c9("9.png");
CImg<unsigned char> c4("4.png");
CImg<unsigned char> cjack("jack.png");
// Declare output and intermediate variables
CImg<unsigned char> row0,row1,grid;
// Append horizontally into a row, you could append many - you are not restricted to 2
row0 = c7.append(cjack,'x');
// Append horizontally into a row
row1 = c4.append(c9,'x');
// Append vertically into a column
grid = row0.append(row1,'y');
grid.display();
}
原答案
最简单的方法可能是 附加 像这样的图像:
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> c7("7.png");
CImg<unsigned char> c9("9.png");
CImg<unsigned char> cjack("jack.png");
CImg<unsigned char> row;
row = c7.append(cjack,'y').append(c9,'y');
row.display();
}
这给出了这个:
如果您将 append()
的 'y'
轴参数更改为 'x'
,它们将并排附加:
CImg<unsigned char> col;
col = c7.append(cjack,'x').append(c9,'x');
col.display();
所以,你现在应该可以看到如何制作网格了。
如何将多张卡片(52 张卡片)图像显示到一张 'grid' 中?
我正在尝试在左上角创建四个桩,在右上角创建四个桩,使用 CImg
class 构成我游戏的主要 table 的八个桩.
CImg本身就有非常基本的显示图像的能力windows。您所能做的就是显示多个图像,使用 CImgDisplay 结构将它们沿其中一个轴对齐。请参阅 CImgDisplay::display() method 的文档。您可以尝试使用 4 个可用轴,看看它是否符合您的需求。
如果这对你来说还不够,你必须使用一些外部库来显示。
更新答案
您可以这样使用 append()
:
#include "CImg.h"
using namespace cimg_library;
int main() {
// Load up all images into CImg structures
CImg<unsigned char> c7("7.png");
CImg<unsigned char> c9("9.png");
CImg<unsigned char> c4("4.png");
CImg<unsigned char> cjack("jack.png");
// Declare output and intermediate variables
CImg<unsigned char> row0,row1,grid;
// Append horizontally into a row, you could append many - you are not restricted to 2
row0 = c7.append(cjack,'x');
// Append horizontally into a row
row1 = c4.append(c9,'x');
// Append vertically into a column
grid = row0.append(row1,'y');
grid.display();
}
原答案
最简单的方法可能是 附加 像这样的图像:
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> c7("7.png");
CImg<unsigned char> c9("9.png");
CImg<unsigned char> cjack("jack.png");
CImg<unsigned char> row;
row = c7.append(cjack,'y').append(c9,'y');
row.display();
}
这给出了这个:
如果您将 append()
的 'y'
轴参数更改为 'x'
,它们将并排附加:
CImg<unsigned char> col;
col = c7.append(cjack,'x').append(c9,'x');
col.display();
所以,你现在应该可以看到如何制作网格了。