~~~~我的生活,我的点点滴滴!!
要想在Qt5 中使用zbar,就得在android环境下编译出.so库,从没开发过android,也没有开发环境,其实我不想搭建,本身就不打算在原生态android中开发android的程序,那这就是一个问题了,如何生这个文件了,我们发现在
java使用c、c++其实是使用的NDK这个工具在编译他们,zbar是一个c、c++的开源库,我们何不尝试着用NDK编译一下zbar了,我们使用eclips来管理工程 ,这里我不给出具体的编译过程了,大家直接下载我的库就好了
迫不及待添加到Qt 工程中使用,发现报了一个很恶心的错误,zbar在使用过程中需要把QImage转换成他能使用的Image,然后在去执行解析,但是尼吗 zbar 使用的QImage 是 qt3的函数接口,我们之所以能在qt4正常使用zbar,那是因为qt4 支持qt3,心都凉了半截了,报错的文件是
QZBarImage.h,我们进去看看内容
#ifndef _QZBARIMAGE_H_
#define _QZBARIMAGE_H_
/// @file
/// QImage to Image type conversion wrapper
#include <qimage.h>
#include <zbar.h>
namespace zbar {
/// wrap a QImage and convert into a format suitable for scanning.
class QZBarImage
: public Image
{
public:
/// construct a zbar library image based on an existing QImage.
QZBarImage (const QImage &qimg)
: qimg(qimg)
{
QImage::Format fmt = qimg.format();
if(fmt != QImage::Format_RGB32 &&
fmt != QImage::Format_ARGB32 &&
fmt != QImage::Format_ARGB32_Premultiplied)
throw FormatError();
unsigned bpl = qimg.bytesPerLine();
unsigned width = bpl / 4;
unsigned height = qimg.height();
set_size(width, height);
set_format('B' | ('G' << 8) | ('R' << 16) | ('4' << 24));
unsigned long datalen = qimg.byteCount();
set_data(qimg.bits(), datalen);
if((width * 4 != bpl) ||
(width * height * 4 > datalen))
throw FormatError();
}
private:
QImage qimg;
};
};
#endif
发现什么了没,他写了一个内联的c++构造函数,并且功能只是把传进来的QImage转换成Image,这样写的话,我们就不用重新编译ZBar+Qt5了,因为他没有把内容生成到.so文件中,我只要理解他原来的用意,然后用Qt5中QImage相应的函数接口去处理就好了 。我太机智了!!!!!
下面附上我编译出来的libs与新的include在此,直接下载就能用了,也不用在麻烦的自己去编译zbar了。