如何使用“ CImg”及其基本功能

用户名

我一直在尝试了解如何使用CImg的绘图功能,但是文档对我来说不是很清楚。我只想绘制一个像素,但不了解draw_point的工作原理。有人可以举一些draw_point以及如何声明图像的示例吗?另外,对于C ++,还有更好的选择吗?我只想要C ++最简单的映像库。我想逐像素处理一个空图像。有更好的选择吗?

Podgorskiy

我已经修改了CImg教程,以显示如何使用draw_point,代码如下:

#include "CImg.h"

using namespace cimg_library;

int main() 
{

    int size_x = 640;
    int size_y = 480;
    int size_z = 1;
    int numberOfColorChannels = 3; // R G B
    unsigned char initialValue = 0;

    CImg<unsigned char> image(size_x, size_y, size_z, numberOfColorChannels, initialValue);

    CImgDisplay display(image, "Click a point");

    while (!display.is_closed())
    {
        display.wait();
        if (display.button() && display.mouse_y() >= 0 && display.mouse_x() >= 0)
        {
            const int y = display.mouse_y();
            const int x = display.mouse_x();

            unsigned char randomColor[3];
            randomColor[0] = rand() % 256;
            randomColor[1] = rand() % 256;
            randomColor[2] = rand() % 256;

            image.draw_point(x, y, randomColor);
        }
        image.display(display);
    }
    return 0;
}

方法draw_point具有三个重载,这可能会混淆使用。我用了以下之一:

template<typename tc>
CImg<T>& draw_point(const int x0, const int y0,
                    const tc *const color, const float opacity=1)

请参阅了解详情。

至于替代方案,如果您只想逐像素修改数据,也许可以使用libpng和libjpeg作为输入/输出来处理图像和原始数据。

无论如何,我建议您阅读有关CImg的更多文档。我已经在一些项目中使用过它,对我来说它非常方便。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

JavaScript使用变量的基本功能

来自分类Dev

如何在C中实现基本功能

来自分类Dev

使用Matlab中的基本功能重建图像

来自分类Dev

使用Matlab中的基本功能重建图像

来自分类Dev

如何使用平滑的术语和具有独立数据的基本功能来预测GAM?

来自分类Dev

摩卡的基本功能如何在“描述/之前/之前”实现?

来自分类Dev

如何重写UserManager.GetRolesAsync(TKey userId)的基本功能

来自分类Dev

如何解决 Azure 基本功能应用程序错误

来自分类Dev

使用QString基本功能从路径获取文件名

来自分类Dev

R:基本功能无法使用Caper包中的对象

来自分类Dev

Haskell基本功能

来自分类Dev

如何通过使用Windows裸露的基本功能来简单地将文件保持在打开状态而无需使用C语言等程序的帮助?

来自分类Dev

cljc文件的基本功能

来自分类Dev

获取python基本功能列表

来自分类Dev

在Haskell中创建基本功能

来自分类Dev

基本功能帮助-Python

来自分类Dev

对象返回中的基本功能

来自分类Dev

基本功能的奇怪行为

来自分类Dev

AngularJS中的基本功能

来自分类Dev

对象返回中的基本功能

来自分类Dev

C ++需要基本功能的指导

来自分类Dev

JavaScript:后退/前进的基本功能

来自分类Dev

Unity基本功能说明

来自分类Dev

基本功能N cov / contravariance

来自分类Dev

MATLAB中的基本功能

来自分类Dev

球拍基本功能列表

来自分类Dev

mangoose 加入 mangodb 的基本功能?

来自分类Dev

该功能是否覆盖基本功能?

来自分类Dev

与基本功能同名的球拍宏功能