Qt5 for android + zbar

~~~~我的生活,我的点点滴滴!!

要想在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了。

zbar for android

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值