Skip to content

Commit

Permalink
!1 save_dict 考虑使用已经打开的dict文件路径?
Browse files Browse the repository at this point in the history
Merge pull request !1 from lalallalala/master
  • Loading branch information
WallBreaker2 authored and gitee-org committed Jun 27, 2021
2 parents 4e004d8 + d1b9227 commit e2f52ba
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions qttool/Tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,24 @@ void Tool::load_dict() {
}

void Tool::save_dict() {
auto dir = QFileDialog::getSaveFileName(this, "save path", "", tr("dict(*.dict)"));
if (!dir.isEmpty()) {
saved = true;
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray ba = dir.toLocal8Bit();
file_dict.write_dict(ba.data());
}
QString dictfile = ui.editPath->text();

if (dictfile.isEmpty() == false)
{
saved = true;
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray ba = dictfile.toLocal8Bit();
file_dict.write_dict(ba.data());
}
else {
auto dir = QFileDialog::getSaveFileName(this, "save path", "", tr("dict(*.dict)"));
if (!dir.isEmpty()) {
saved = true;
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray ba = dir.toLocal8Bit();
file_dict.write_dict(ba.data());
}
}
}

void Tool::add_word() {
Expand Down Expand Up @@ -582,31 +593,31 @@ void Tool::capture_full_screen() {
_width = rc.right - rc.left;
_height = rc.bottom - rc.top;
//qDebug() << _width << "," << _height;
_hmdc = CreateCompatibleDC(_hdc); //创建一个与指定设备兼容的内存设备上下文环境
_hmdc = CreateCompatibleDC(_hdc); //创建一个与指定设备兼容的内存设备上下文环境
if (_hmdc == NULL) {
//Tool::setlog("CreateCompatibleDC false");
//return -2;
}
_hbmpscreen = CreateCompatibleBitmap(_hdc, _width, _height); //创建与指定的设备环境相关的设备兼容的位图
_hbmpscreen = CreateCompatibleBitmap(_hdc, _width, _height); //创建与指定的设备环境相关的设备兼容的位图

_holdbmp = (HBITMAP)SelectObject(_hmdc, _hbmpscreen); //选择一对象到指定的设备上下文环境中
_holdbmp = (HBITMAP)SelectObject(_hmdc, _hbmpscreen); //选择一对象到指定的设备上下文环境中


GetObject(_hbmpscreen, sizeof(_bm), (LPSTR)&_bm); //得到指定图形对象的信息
GetObject(_hbmpscreen, sizeof(_bm), (LPSTR)&_bm); //得到指定图形对象的信息
//BITMAPINFOHEADER _bih;
_bih.biBitCount = _bm.bmBitsPixel;//每个像素字节大小
_bih.biBitCount = _bm.bmBitsPixel;//每个像素字节大小
_bih.biCompression = BI_RGB;
_bih.biHeight = _bm.bmHeight;//高度
_bih.biHeight = _bm.bmHeight;//高度
_bih.biPlanes = 1;
_bih.biSize = sizeof(BITMAPINFOHEADER);
_bih.biSizeImage = _bm.bmWidthBytes * _bm.bmHeight;//图像数据大小
_bih.biWidth = _bm.bmWidth;//宽度
_bih.biSizeImage = _bm.bmWidthBytes * _bm.bmHeight;//图像数据大小
_bih.biWidth = _bm.bmWidth;//宽度
BitBlt(_hmdc, 0, 0, _width, _height, _hdc, 0, 0, SRCCOPY);
//if (_pimagedata)
// delete[] _pimagedata;
//_pimagedata = new byte[_width*_height * 4];
_imagedata.reserve(_width * _height * 4);
//函数获取指定兼容位图的位,然后将其作一个DIB—设备无关位图(Device-Independent Bitmap)使用的指定格式复制到一个缓冲区中
//函数获取指定兼容位图的位,然后将其作一个DIB—设备无关位图(Device-Independent Bitmap)使用的指定格式复制到一个缓冲区中
GetDIBits(_hmdc, _hbmpscreen, 0L, (DWORD)_height, (LPBYTE)_imagedata.data(), (LPBITMAPINFO)&_bih, (DWORD)DIB_RGB_COLORS);

}
Expand All @@ -632,7 +643,7 @@ void Tool::to_mat() {
int y1 = _cap_dlg.srect.top();
for (int i = 0; i < ch; ++i) {
p = _imgloc._src.ptr<uchar>(i);
p2 = _imagedata.data() + (_height - i - 1 - y1) * _width * 4 + x1 * 4;//偏移
p2 = _imagedata.data() + (_height - i - 1 - y1) * _width * 4 + x1 * 4;//偏移
for (int j = 0; j < cw; ++j) {
*p++ = *p2++; *p++ = *p2++;
*p++ = *p2++; *p++ = *p2++;
Expand Down

0 comments on commit e2f52ba

Please sign in to comment.