HGGitLab

Commit 0ece8a6e authored by luoliangyi's avatar luoliangyi

解决扫描文件dpi不正确的问题

parent 9da47822
......@@ -43,11 +43,12 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("cancel"));
//Temporarily hide some functions
ui->cbtn_subFolderByBlank->setEnabled(false);
ui->cbtn_subFolderByColor->setEnabled(false);
ui->cbox_evenOdd->setEnabled(false);
ui->radio_multiCustom->setEnabled(false);
ui->spinBox_multiPages->setEnabled(false);
ui->cbtn_subFolderByBlank->setVisible(false);
ui->cbtn_subFolderByColor->setVisible(false);
ui->cbox_evenOdd->setVisible(false);
ui->radio_multiAll->setVisible(false);
ui->radio_multiCustom->setVisible(false);
ui->spinBox_multiPages->setVisible(false);
}
Dialog_AquireInto::~Dialog_AquireInto()
......
......@@ -36,6 +36,60 @@
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
static std::string Utf8ToAnsi(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_UTF8, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pAnsi = new CHAR[len];
::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pAnsi;
delete[] pAnsi;
return ret;
}
#endif
static std::string Utf8ToStdString(const char* utf8)
{
#if defined(HG_CMP_MSC)
return Utf8ToAnsi(utf8);
#else
return utf8;
#endif
}
static std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
static void TrimString(std::string& str)
{
int s = (int)str.find_first_not_of(" ");
int e = (int)str.find_last_not_of(" ");
str = str.substr(s, e - s + 1);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
......@@ -776,6 +830,34 @@ void MainWindow::on_new_image(void *img)
{
HGImage image = (HGImage)img;
HGUInt dpi = 96;
SANE_Int num_dev_options = 0;
sane_control_option(m_saneDeviceHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
for (int i = 1; i < num_dev_options; ++i)
{
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_saneDeviceHandle, i);
if (NULL == desp)
continue;
std::string title = Utf8ToStdString(desp->title);
TrimString(title);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "title=%s", title.c_str());
if (SANE_TYPE_INT == desp->type)
{
SANE_Int value = 0;
sane_control_option(m_saneDeviceHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=INT, value=%d", value);
if (0 == strcmp(title.c_str(), "ֱ"))
{
dpi = value;
}
}
}
HGBase_SetImageDpi(image, dpi, dpi);
if (1 == m_scanType)
{
if (-1 == m_scanInsertPos)
......@@ -1756,7 +1838,7 @@ int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigne
imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP};
HGImage img = nullptr;
HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, imgType, HGBASE_IMGORIGIN_TOP, &img);
if (nullptr != img)
{
emit p->new_image(img);
......@@ -2206,6 +2288,14 @@ void MainWindow::on_act_acquireInto_triggered()
m_scanType = 2;
m_aquireIntoSaveParam = dlg.getSaveParam();
if (m_aquireIntoSaveParam.m_isUseSubfolderByTime)
{
QDate date = QDate::currentDate();
QString str = date.toString("yyyy-MM-dd");
m_aquireIntoSaveParam.m_savePath += "/";
m_aquireIntoSaveParam.m_savePath += str;
}
if (!startSpaceCheck(this))
{
m_dialogLog->updateStatus(nullptr != m_saneDeviceHandle && 0 != m_scanType, m_isScanning);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment