在C ++上使用CImg类显示多个图像 [英] Display several images using CImg class on C++

查看:169
本文介绍了在C ++上使用CImg类显示多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一张卡片(52张卡片)的几张图像显示为一个网格"? 我正在尝试使用CImg类在左上角创建四个桩,在右上角创建四个桩,八个桩组成游戏的主表.

How can one display several images of cards (52 cards) into a 'grid'? I am trying to create four piles in the upper left corner, four piles in the upper right corner, eight piles that make up the main table for my game with the use of CImg class.

推荐答案

更新后的答案

您可以像这样使用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();
}

原始答案

最简单的方法可能是像这样附加图像:

The easiest way is probably to append images like this:

#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',它们将并排附加:

If you change the 'y' axis parameter for append() to 'x' they will append side-by-side:

   CImg<unsigned char> col;
   col = c7.append(cjack,'x').append(c9,'x');
   col.display();

因此,您现在应该能够了解如何制作网格.

So, you should be able to see how to make a grid now.

这篇关于在C ++上使用CImg类显示多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆