mirror of
https://github.com/zxing/zxing.git
synced 2024-11-14 15:04:05 -08:00
f78c18671b
By V1.2 support to Aztec codes is added. It now fully supports Qt Quick. Symbian Examples are updated to comply with the changes. git-svn-id: https://zxing.googlecode.com/svn/trunk@2296 59b500cc-1b3d-0410-9834-0bbf25fbcc57
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#include "imagehandler.h"
|
|
#include <QGraphicsObject>
|
|
#include <QImage>
|
|
#include <QPainter>
|
|
#include <QStyleOptionGraphicsItem>
|
|
#include <QDebug>
|
|
|
|
ImageHandler::ImageHandler(QObject *parent) :
|
|
QObject(parent)
|
|
{
|
|
}
|
|
|
|
QImage ImageHandler::extractQImage(QObject *imageObj,
|
|
const double offsetX, const double offsetY,
|
|
const double width, const double height)
|
|
{
|
|
QGraphicsObject *item = qobject_cast<QGraphicsObject*>(imageObj);
|
|
|
|
if (!item) {
|
|
qDebug() << "Item is NULL";
|
|
return QImage();
|
|
}
|
|
|
|
QImage img(item->boundingRect().size().toSize(), QImage::Format_RGB32);
|
|
img.fill(QColor(255, 255, 255).rgb());
|
|
QPainter painter(&img);
|
|
QStyleOptionGraphicsItem styleOption;
|
|
item->paint(&painter, &styleOption);
|
|
|
|
if(offsetX == 0 && offsetY == 0 && width == 0 && height == 0)
|
|
return img;
|
|
else
|
|
{
|
|
return img.copy(offsetX, offsetY, width, height);
|
|
}
|
|
}
|
|
|
|
void ImageHandler::save(QObject *imageObj, const QString &path,
|
|
const double offsetX, const double offsetY,
|
|
const double width, const double height)
|
|
{
|
|
QImage img = extractQImage(imageObj, offsetX, offsetY, width, height);
|
|
img.save(path);
|
|
}
|