最简单的绘制图像的方法? [英] The easiest way to draw an image?

查看:88
本文介绍了最简单的绘制图像的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Assume you want to read an image file in a common file format from the hard drive, change the color of one pixel, and display the resulting image to the screen, in C++.

您建议使用最少量的代码完成上述哪些(开源)库?

Which (open-source) libraries would you recommend to accomplish the above with the least amount of code?

最优雅的方式?

一些背景:我最近一直在读大量的计算机图形文学,有很多相对容易,基于像素的算法我想实现。然而,虽然算法本身通常是直接实现的,但是在每个像素的基础上操作图像所需的框架工作量并显示结果阻止了我这样做。

A bit of background: I have been reading a lot of computer graphics literature recently, and there are lots of relatively easy, pixel-based algorithms which I'd like to implement. However, while the algorithm itself would usually be straightforward to implement, the necessary amount of frame-work to manipulate an image on a per-pixel basis and display the result stopped me from doing it.

推荐答案

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

它也可以用作一个相当强大的图像处理图书馆。请参阅示例此处

It can also be used as a rather powerful image processing library. See the examples here.

这篇关于最简单的绘制图像的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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