创建 CImg;来自字节数组?
我正在尝试修改一个 C++ 库,该库具有从图像文件创建 CImg 实例的函数,以改为使用字节数组。这可能吗?我找到了一种似乎允许这样做的方法...
CImg ( const t *const values,
const unsigned int size_x,
const unsigned int size_y = 1,
const unsigned int size_z = 1,
const unsigned int size_c = 1,
const bool is_shared = false
)
...但由于我拥有的只是字节数组,所以我没有源图像的尺寸。
更新以解决评论 这是对 pHash 库进行修改的尝试,该库使用此处定义的 CImg 类 http: //cimg.sourceforge.net/reference/structcimg__library_1_1CImg.html
字节数组通过源图像的 http 请求填充。
I'm trying to modify a C++ library that has a function that creates a CImg instance from an image file, to use a byte array instead. Is this possible? I found one method that appears to allow it...
CImg ( const t *const values,
const unsigned int size_x,
const unsigned int size_y = 1,
const unsigned int size_z = 1,
const unsigned int size_c = 1,
const bool is_shared = false
)
...but since all I have is the byte array, I don't have the dimensions of the source image.
UPDATED TO ADDRESS COMMENTS
This is an attempt to make a modification to the pHash library, which uses the CImg class as defined here http://cimg.sourceforge.net/reference/structcimg__library_1_1CImg.html
The byte array is populated through an http request for the source image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的字节数组包含整个图像文件的副本(而不仅仅是位图部分),那么您可以从标头读取尺寸。
请参阅
BITMAPFILEHEADER
和BITMAPINFOHEADER
(当然,对于其他格式(例如 PNG 或 JPEG),您将需要相应的标头)。例如,这将允许您查看来自网络或应用程序资源段的图像,而无需先将其写入磁盘。
If your byte array contains a copy of the entire image file (not just the bitmap portion), then you can read the dimensions from the header.
See
BITMAPFILEHEADER
andBITMAPINFOHEADER
(of course, for other formats such as PNG or JPEG, you'll need the corresponding headers).For example, this will let you view an image from the network or your application resource segment, without first writing it to disk.