简体   繁体   English

用C ++输出图片的快速方法

[英]Quick way to output a picture in C++

I'm coding a physical simulation on 2d array and I'm now thinking that I could benefit from having a graphical output. 我正在2D数组上进行物理模拟编码,现在正在考虑可以从图形输出中受益。 My system is an array of cells (up to 2048*2048 of them) taking binary values, until now I used a prompt or text file output of '+' and '-' but it's not efficient for 2048*2048 lattice and maybe outputting in an image would be quicker and neater. 我的系统是一个采用二进制值的单元格数组(最多2048 * 2048个),直到现在我使用的提示或文本文件输出为“ +”和“-”,但对于2048 * 2048格效率不高,也许输出在图像中会更快更整洁。 Still, I've never done that. 不过,我从未做到过。 Ideally a library allowing me to write blue and red pixels/cell while parsing my lattice would get the job done. 理想情况下,允许我在解析晶格的同时编写蓝色和红色像素/单元的库可以完成工作。 Are there some pre-existing not too long tools for doing it in c++? 是否有一些预先存在的不太长的工具可以在c ++中实现?

Edit: I think that I just found what I was looking for: png++ 编辑:我认为我刚刚找到了我想要的东西: png ++

After no more than 10 lines of coding I got the following output: 经过不超过10行编码后,我得到以下输出: 是的,我最后使用绿色而不是蓝色...

All I was asking for! 我所有的要求! Thank you for the suggestions ;) 感谢你的建议 ;)

You can easily get away without using an external imaging library by outputting a very simple format such as PGM or PBM. 通过输出非常简单的格式(例如PGM或PBM),无需使用外部映像库即可轻松摆脱困境。 Refer to the wikipedia page on Netbpm for more details, but you're essentially outputting all the values as either ASCII or binary numbers, then any image viewer or editor that supports PGM (many of which do) can open and display them. 有关更多详细信息,请参阅Netbpm上的Wikipedia页面 ,但实际上您将所有值输出为ASCII或二进制数字,然后任何支持PGM的图像查看器或编辑器(其中有很多)都可以打开并显示它们。 Even if you don't have an editor, something like ImageMagick can easily convert it to a PNG or any other more accessible format. 即使您没有编辑器,诸如ImageMagick之类的东西也可以轻松将其转换为PNG或其他任何更易访问的格式。

I've used this technique in the past to quickly visualize 2D data, as you're intending to. 正如您打算的那样,我过去曾使用此技术来快速可视化2D数据。

C++ does not have native support for graphics. C ++没有图形的本机支持。 You need an additional C++ library. 您需要一个附加的C ++库。

Personally, I suggest you to use Qt , which is free, powerful and cross-platform. 就个人而言,我建议您使用Qt ,它是免费,强大且跨平台的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM