Added decodeImageQML taken from https://github.com/dplanella/qzxing/blob/master/qzxing.cpp. This is to be used in Qt versions 5.0 and above. Code cleanup needs to be done as well as updates to the examples.

This commit is contained in:
favoritas37 2014-09-19 00:19:54 +03:00
parent 84cf4482f2
commit 357b658029
2 changed files with 51 additions and 11 deletions

View File

@ -87,18 +87,35 @@ public slots:
QString decodeImageFromFile(QString imageFilePath, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false);
/**
* The decoding function accessible from QML
*/
* The decoding function accessible from QML. (Suggested for Qt 4.x)
*/
QString decodeImageQML(QObject *item);
/**
* The decoding function accessible from QML. Able to set the decoding
* of a portion of the image.
*/
* The decoding function accessible from QML. Able to set the decoding
* of a portion of the image. (Suggested for Qt 4.x)
*/
QString decodeSubImageQML(QObject* item,
const double offsetX = 0 , const double offsetY = 0,
const double width = 0, const double height = 0);
/**
* The decoding function accessible from QML. (Suggested for Qt 5.x)
* Can be used to decode image from the Camera element preview by providing
* the following string: image://camera/preview_1
*/
QString decodeImageQML(const QUrl &imageUrl);
/**
* The decoding function accessible from QML. Able to set the decoding
* of a portion of the image.
* Can be used to decode image from the Camera element preview by providing
* the following string: image://camera/preview_1
* (Suggested for Qt 5.x)
*/
QString decodeSubImageQML(const QUrl &imageUrl,
const double offsetX = 0, const double offsetY = 0,
const double width = 0, const double height = 0);
/**
* Get the prossecing time in millisecond of the last decode operation.
* Added mainly as a statistic measure.

View File

@ -135,17 +135,17 @@ QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoo
}
catch(zxing::Exception& e)
{
emit decodingFinished(false);
processingTime = -1;
return "";
emit decodingFinished(false);
processingTime = -1;
return "";
}
}
QString QZXing::decodeImageFromFile(QString imageFilePath, int maxWidth, int maxHeight, bool smoothTransformation)
{
//used to have a check if this image exists
//but was removed because if the image file path doesn't point to a valid image
// then the QImage::isNull will return true and the decoding will fail eitherway.
//used to have a check if this image exists
//but was removed because if the image file path doesn't point to a valid image
// then the QImage::isNull will return true and the decoding will fail eitherway.
return decodeImage(QImage(imageFilePath), maxWidth, maxHeight, smoothTransformation);
}
@ -169,6 +169,29 @@ QString QZXing::decodeSubImageQML(QObject* item,
return decodeImage(img);
}
QString QZXing::decodeImageQML(const QUrl &imageUrl)
{
return decodeSubImageQML(imageUrl);
}
QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
const double offsetX, const double offsetY,
const double width, const double height)
{
QString imagePath = imageUrl.path();
imagePath = imagePath.trimmed();
QFile file(imagePath);
if (!file.exists()) {
qDebug() << "[decodeSubImageQML()] The file" << file.fileName() << "does not exist.";
emit decodingFinished(false);
return "";
}
QImage img(imageUrl.path());
if(!(offsetX == 0 && offsetY == 0 && width == 0 && height == 0)) {
img = img.copy(offsetX, offsetY, width, height);
}
return decodeImage(img);
}
int QZXing::getProcessTimeOfLastDecoding()
{
return processingTime;