int ConvertImageFileToChar( QString strImageFile, char *pPlateImageChar)
{
QFile file(strImageFile);
if (!file.exists()) {
return -1;
}
QByteArray arrayData;
if (file.open(QIODevice::ReadOnly))
{
arrayData = file.readAll();
file.close();
}
else {
return -1;
}
if (arrayData.size() <= 0) {
return -1;
}
int imageLen = arrayData.size();
if (pPlateImageChar != NULL) {
memcpy(pPlateImageChar, arrayData.data(), imageLen);
}
return imageLen;
}
void WriteImageData(char* pImageData, int iDataLen, QString strFileName)
{
QString strLogPath = QCoreApplication::applicationDirPath() + "/" + "Log" + "/" + "JpgFile";
QDir dir(strLogPath);
if (!dir.exists()) {
dir.mkpath(strLogPath);
}
strFileName = strLogPath + "/" + strFileName + ".jpg";
QImage image;
image.loadFromData(reinterpret_cast<unsigned char*>(pImageData), iDataLen);
image.save(strFileName);
}
int ConvertImageFileToBase64(QStringList strImageFileList, QStringList &strImageBase64List)
{
for (int i = 0; i < strImageFileList.count(); i++)
{
QString strImageBase64 = "";
QFile file(strImageFileList.at(i));
if (!file.exists())
{
strImageBase64List << strImageBase64;
continue;
}
if (file.open(QIODevice::ReadOnly))
{
QByteArray fileByteArray = file.readAll();
if (!fileByteArray.isEmpty()) {
strImageBase64 = QString(fileByteArray.toBase64());
}
file.close();
}
strImageBase64List << strImageBase64;
}
return 0;
}
int ConvertImageDataToBase64(QStringList strImageFileList, QStringList &strImageBase64List)
{
for (int i = 0; i < strImageFileList.count(); i++)
{
QString strImageBase64 = "";
if (!QFile::exists(QString(strImageFileList.at(i))))
{
strImageBase64List << strImageBase64;
continue;
}
QImage image = QImage(strImageFileList.at(i));
if (!image.isNull())
{
QByteArray arrayData;
QBuffer buffer(&arrayData);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer,"JPG");
if (!arrayData.isEmpty())
{
QByteArray arrayBase64Data = arrayData.toBase64();
strImageBase64 = QString(arrayBase64Data);
}
buffer.close();
}
strImageBase64List << strImageBase64;
}
return 0;
}