绘制图像最简单的方法是什么?

时间:2011-01-01 22:47:55

标签: c++ graphics image-processing

假设您想要从硬盘驱动器中读取通用文件格式的图像文件,更改一个像素的颜色,并在C ++中将结果图像显示在屏幕上。

您建议哪些(开源)库以最少的代码完成上述工作?

或者,哪些库可以以最优雅的方式执行上述操作?

一些背景知识:我最近一直在阅读大量的计算机图形文献,并且我想实现许多相对简单的基于像素的算法。然而,虽然算法本身通常很容易实现,但是以每个像素为基础操作图像并显示结果所需的帧工作量使我不能这样做。

3 个答案:

答案 0 :(得分:9)

CImg库易于使用。

CImg<unsigned char> img("lena.png");              // Read in the image lena.png
const unsigned char valR = img(10,10,0,0);        // Read the red component at coordinates (10,10)
const unsigned char valG = img(10,10,0,1);        // Read the green component at coordinates (10,10)
const unsigned char valB = img(10,10,2);          // Read the blue component at coordinates (10,10) (Z-coordinate omitted here).
const unsigned char avg = (valR + valG + valB)/3; // Compute average pixel value.
img(10,10,0) = img(10,10,1) = img(10,10,2) = avg; // Replace the pixel (10,10) by the average grey value.
CImgDisplay main_disp(img, "Modified Lena");      // Display the modified image on the screen
img.save("lena_mod.png");                         // Save the modified image to lena_mod.png

它还可以用作相当强大的图像处理库。请参阅示例here

答案 1 :(得分:4)

您应该查看OpenCV库,特别是如果您正在对计算机图形进行理论研究。

答案 2 :(得分:0)

如果目标应用程序仅限Windows,您可以使用GDI +,描述为hereherehere是使用GDI +进行图像处理的众多概念证据之一。

编辑:库不是开源的,自Windows XP以来就包含在操作系统中(可以安装在98和2000上),API是公开的,它为您提供了许多手头的图像处理功能,可用于更复杂的算法