优化字体图片阈值设定

This commit is contained in:
gb 2024-02-06 14:14:21 +08:00
parent 16466d41ad
commit 02a105fde3
5 changed files with 63 additions and 10 deletions

View File

@ -80,6 +80,18 @@ BOOL CDlgZk::OnInitDialog()
SetDlgItemInt(IDC_EDIT_SIZE_W, 16);
SetDlgItemInt(IDC_EDIT_SIZE_H, 16);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN5))->SetRange(0, 255);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN5))->SetPos(127);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1))->SetRange(-64, 128);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1))->SetPos(0);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2))->SetRange(-16, 32);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2))->SetPos(0);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN3))->SetRange(8, 128);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN3))->SetPos(16);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN4))->SetRange(8, 32);
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN4))->SetPos(16);
threshold_.SetRange(0, 255);
threshold_.SetPos(127);
@ -105,11 +117,8 @@ BOOL CDlgZk::OnInitDialog()
return TRUE; // return TRUE unless you set the focus to a control
}
void CDlgZk::regen(void)
LRESULT CDlgZk::regen(WPARAM wp, LPARAM lp)
{
if (!initialized_)
return;
std::wstring f(get_item_text(IDC_COMBO_FONT)),
fs(get_item_text(IDC_COMBO_SIZE)),
t(get_item_text(IDC_EDIT_DATA)),
@ -122,20 +131,28 @@ void CDlgZk::regen(void)
HWND hwnd = GetDlgItem(IDC_STATIC_DRAW)->m_hWnd;
HDC hdc = ::GetDC(hwnd);
char_dc dc(hdc);
uint8_t *ptr = NULL;
uint8_t * ptr = NULL;
bool picture = ((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck() == BST_CHECKED;
if (picture)
{
bool stretch = ((CButton*)GetDlgItem(IDC_CHECK2))->GetCheck() == BST_CHECKED;
if(bmp_)
ptr = dc.lattice(bmp_, threshold_.GetPos(), out, off, stretch);
else
ptr = dc.lattice(pic_.c_str(), threshold_.GetPos(), out, off, stretch);
if (ptr)
int thr = _wtoi(get_item_text(IDC_EDIT_THRESHOLD).c_str()); // threshold_.GetPos();
if (bmp_)
{
ptr = dc.lattice(bmp_, thr, out, off, stretch);
swprintf_s(text, _countof(text) - 1, L"mem_%X", bmp_);
sep = text;
}
else
{
ptr = dc.lattice(pic_.c_str(), thr, out, off, stretch);
sep = pic_;
STR_FILE_NAME(sep, false);
}
if (ptr)
{
os = std::wstring(L"font_map_[\"") + sep + L"\"] = " + sep + L";";
sep.insert(0, L"static uint8_t ");
sep += L"[] = {" + std::to_wstring(out.cx) + L", " + std::to_wstring(out.cy) + L"\r\n\t\t";
@ -161,6 +178,8 @@ void CDlgZk::regen(void)
threshold_.EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_CHECK2))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_THRESHOLD)->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_SPIN5))->EnableWindow(FALSE);
sep = L"";
}
}
@ -205,6 +224,16 @@ void CDlgZk::regen(void)
::ReleaseDC(hwnd, hdc);
::SetDlgItemTextW(m_hWnd, IDC_EDIT_STATUS, sep.c_str());
return 0;
}
void CDlgZk::regen(void)
{
if (!initialized_)
return;
//GetDlgItem(IDC_STATIC_DRAW)->InvalidateRect(NULL);
::PostMessage(m_hWnd, WM_USER + 1, 0, 0);
}
BEGIN_MESSAGE_MAP(CDlgZk, CDialogEx)
@ -218,9 +247,11 @@ BEGIN_MESSAGE_MAP(CDlgZk, CDialogEx)
ON_EN_CHANGE(IDC_EDIT_OFF_Y, &CDlgZk::OnEnChangeEditPos)
ON_EN_CHANGE(IDC_EDIT_SIZE_W, &CDlgZk::OnEnChangeEditPos)
ON_EN_CHANGE(IDC_EDIT_SIZE_H, &CDlgZk::OnEnChangeEditPos)
ON_EN_CHANGE(IDC_EDIT_THRESHOLD, &CDlgZk::OnEnChangeEditPos)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, &CDlgZk::OnNMReleasedcaptureSlider1)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BUTTON1, &CDlgZk::OnBnClickedButton1)
ON_MESSAGE(WM_USER + 1, &CDlgZk::regen)
END_MESSAGE_MAP()
@ -266,6 +297,8 @@ void CDlgZk::OnBnClickedCheck1()
threshold_.EnableWindow(picture);
((CButton*)GetDlgItem(IDC_CHECK2))->EnableWindow(picture);
((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(picture);
GetDlgItem(IDC_EDIT_THRESHOLD)->EnableWindow(picture);
((CButton*)GetDlgItem(IDC_SPIN5))->EnableWindow(picture);
pic_ = L"";
if (bmp_)
DeleteObject(bmp_);
@ -330,6 +363,23 @@ void CDlgZk::OnBnClickedButton1()
{
if (::MessageBoxW(m_hWnd, L"剪贴板有图像,需要使用吗?", L"剪贴板图像", MB_YESNO) == IDYES)
{
BITMAP bm = { 0 };
if (GetObject(bmp_, sizeof(bm), &bm))
{
HDC dc = ::GetDC(m_hWnd),
hdc = ::CreateCompatibleDC(dc),
hdc0 = ::CreateCompatibleDC(dc);
HBITMAP bmp = ::CreateCompatibleBitmap(dc, bm.bmWidth, bm.bmHeight),
old = (HBITMAP)::SelectObject(hdc, bmp),
old0 = (HBITMAP)::SelectObject(hdc0, bmp_);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdc0, 0, 0, SRCCOPY);
::SelectObject(hdc0, old0);
::SelectObject(hdc, old);
DeleteDC(hdc0);
DeleteDC(hdc);
::ReleaseDC(m_hWnd, dc);
bmp_ = bmp;
}
regen();
return;
}
@ -347,6 +397,8 @@ void CDlgZk::OnBnClickedButton1()
((CButton*)GetDlgItem(IDC_CHECK1))->SetCheck(BST_UNCHECKED);
((CButton*)GetDlgItem(IDC_CHECK2))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_THRESHOLD)->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_SPIN5))->EnableWindow(FALSE);
threshold_.EnableWindow(FALSE);
}
regen();

View File

@ -226,6 +226,7 @@ class CDlgZk : public CDialogEx
};
void regen(void);
afx_msg LRESULT regen(WPARAM wp, LPARAM lp);
public:
CDlgZk(CWnd* pParent = NULL); // standard constructor

Binary file not shown.

Binary file not shown.

Binary file not shown.