如何使用C++将wxImage存储到数据库中?

发布于 2024-08-27 07:43:58 字数 713 浏览 6 评论 0原文

我有一些 wxImages,我想将它们存储到 BLOB(二进制大型对象)字段。

wxImagewxBitmap 用于获取作为 unsigned char 数组的二进制数据,以便我可以加载到数据库。

我当前的解决方法是将图像写入临时文件,然后直接从该文件加载 BLOB 字段。

是否有更有效的方法来加载 wxImage 对象并将其存储到 MySQL BLOB 字段中?

我正在使用 MySql C++ 连接器 1.05、MS Visual Studio 2008、wxWidgets 和 C++。

I have some wxImages and I would like to store them into a BLOB (Binary Large OBject) field in a MySQL database.

There are no methods in wxImage nor wxBitmap for obtaining the binary data as an array of unsigned char so I can load into the database.

My current workaround is to write the image to a temporary file, then load the BLOB field directly from the file.

Is there a more efficient method to load and store a wxImage object into a MySQL BLOB field?

I am using MySql C++ connector 1.05, MS Visual Studio 2008, wxWidgets and C++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑色毁心梦 2024-09-03 07:43:58

wxWidgets 不为来自 wxBitmap 的数据提供任何 API(因为它依赖于平台),但 wxImage 使用定义明确(且非常简单)的格式,您可以访问该格式使用上面提到的 GetData() 方法。请注意,如果您的图像具有 Alpha 通道,您可能还需要使用 GetAlpha()

然而,这不是我这样做的方式,因为如果你这样做的话,数据将会巨大。虽然如上所述,压缩它是可能的,但当 wxImage 已经支持以任何标准图像格式写入图像时,为什么还要手动进行压缩呢?只需创建一个 wxMemoryOutputStream 并将其传递给 SaveFile() 即可。然后只需使用 GetOutputStreamBuffer()->GetBufferStart() 及相关函数直接访问流缓冲区即可。

wxWidgets doesn't provide any API to the data from wxBitmap (because it's platform-dependent) but wxImage uses a well-defined (and very simple) format which you can access using its GetData() method as mentioned above. Just notice that you may need to use GetAlpha() as well if your images have alpha channel.

However this is not how I'd do it because the data will be huge if you do it like this. While compressing it, as also suggested above, is possible, why bother doing it manually when wxImage already supports writing image in any of the standard image formats. Just create a wxMemoryOutputStream and pass it to SaveFile(). Then simply access the stream buffer directly using GetOutputStreamBuffer()->GetBufferStart() and related functions.

昨迟人 2024-09-03 07:43:58

除非我遗漏了一些东西,否则你不能使用 WxImage::GetData (http:// /docs.wxwidgets.org/2.8/wx_wximage.html#wximagegetdata)来获取数据,然后::GetHeight和::GetWidth来知道指针指向的数据的长度? WxImage::GetData 返回的 unsigned char * 看起来应该指向组成图像的 RGB 数据。

Unless I'm missing something, couldn't you use WxImage::GetData (http://docs.wxwidgets.org/2.8/wx_wximage.html#wximagegetdata) to get the data and then ::GetHeight and ::GetWidth to know the length of the data that pointer points to? The unsigned char * that is returned by WxImage::GetData looks like it should point to the RGB data that makes up the image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文