In C, I have a 1D array of unsigned chars (ie, between 0 to 255) of length 3*DIM*DIM
which represents a DIM*DIM
pixel image, where the first 3 pixels are the RGB levels of the first pixel, the second 3 pixels are the RGB levels of the second pixel, etc. I would like to save it as a PNG image. What is the easiest, most lightweight method of doing this conversion?
在C语言中,我有一个一维数组的无符号字符(即0到255之间)的长度3 *的*暗代表着暗淡的*暗像素图像,其中前3像素的RGB水平第一像素,第二个3像素的RGB水平第二像素,等等。我想将其保存为PNG图像。进行这种转换的最简单、最轻量级的方法是什么?
Obviously OpenGL can read and display images of this form (GLUT_RGB), but DIM
is larger than the dimensions of my monitor screen, so simply displaying the image and taking a screenshot is not an option.
显然,OpenGL可以读取和显示这个表单的图像(GLUT_RGB),但是DIM比我的监视器屏幕的尺寸大,所以简单地显示图像并进行屏幕截图不是一个选项。
At the moment, I have been doing the conversion by simply saving the array to a CSV file, loading it in Mathematica, and then exporting it as a PNG, but this is very slow (~8 minutes for a single 7000*7000 pixel image).
目前,我只需要将数组保存到CSV文件中,装入Mathematica中,然后将其导出为PNG格式,就可以进行转换,但这非常缓慢(对于一个7000*7000像素的图像,大约需要8分钟)。
1 个解决方案
#1
4
There are many excellent third party libraries you can use to convert an array of pixel-data to a picture.
有许多优秀的第三方库可以用来将像素数据数组转换为图片。
- libPNG is a long standing standard library for png images.
- libPNG是一种用于png图像的长期标准库。
- LodePNG also seems like a good candidate.
- LodePNG看起来也不错。
- Finally, ImageMagick is a great library that supports many different image formats.
- 最后,ImageMagick是一个很好的库,它支持许多不同的图像格式。
All these support C, and are relatively easy to use.
所有这些支持C,并且相对容易使用。
#1
4
There are many excellent third party libraries you can use to convert an array of pixel-data to a picture.
有许多优秀的第三方库可以用来将像素数据数组转换为图片。
- libPNG is a long standing standard library for png images.
- libPNG是一种用于png图像的长期标准库。
- LodePNG also seems like a good candidate.
- LodePNG看起来也不错。
- Finally, ImageMagick is a great library that supports many different image formats.
- 最后,ImageMagick是一个很好的库,它支持许多不同的图像格式。
All these support C, and are relatively easy to use.
所有这些支持C,并且相对容易使用。