如何将wxImage存储到数据库中

如何将wxImage存储到数据库中

本文介绍了如何将wxImage存储到数据库中,使用C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

或获取二进制数据作为 unsigned char 所以我可以加载到数据库。

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.

有没有更有效的方法来加载和存储wxImage对象到MySQL BLOB字段?

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

我使用的是MySql C ++连接器1.05,MS Visual Studio 2008,和

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

推荐答案

wxWidgets不提供任何API来自 wxBitmap (因为它是平台相关的),但是 wxImage 使用一个定义明确(非常简单)的格式,你可以使用 GetData )方法。只要注意,如果你的图片有alpha通道,你可能还需要使用 GetAlpha()

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.

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

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.

这篇关于如何将wxImage存储到数据库中,使用C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:13