在位图上绘制符号时出现问题
#include <iostream>
#include <windows.h>
#include <gdiplus.h>
#pragma comment (lib,"Gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int main()
{
HBITMAP hbmp = CreateBitmap(50,50, 1, 1, NULL);
HDC hdc = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
HBRUSH hbrush = CreateSolidBrush(Color::White);
HPEN hpen = CreatePen(PS_SOLID, 1, Color::Black);
HFONT hfont = CreateFont(50, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
ANTIALIASED_QUALITY, DEFAULT_PITCH, TEXT("Times New Roman"));
HGDIOBJ hbmpOld = SelectObject(hdc, hbmp);
HGDIOBJ hbrushOld = SelectObject(hdc, hbrush);
HGDIOBJ hpenOld = SelectObject(hdc, hpen);
HGDIOBJ hfontOld = SelectObject(hdc, hfont);
SetTextColor(hdc, Color::Black);
SetBkColor(hdc, Color::White);
SetBkMode(hdc, OPAQUE);
RECT rect={50,0,50,0};
FillRect(hdc, &rect, hbrush);
DrawText(hdc, "1", -1, &rect, DT_LEFT);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hbmp);
CloseClipboard();
getchar();
}
但在剪贴板中的这段代码之后,我只有黑色方块,没有符号。
#include <iostream>
#include <windows.h>
#include <gdiplus.h>
#pragma comment (lib,"Gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int main()
{
HBITMAP hbmp = CreateBitmap(50,50, 1, 1, NULL);
HDC hdc = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
HBRUSH hbrush = CreateSolidBrush(Color::White);
HPEN hpen = CreatePen(PS_SOLID, 1, Color::Black);
HFONT hfont = CreateFont(50, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
ANTIALIASED_QUALITY, DEFAULT_PITCH, TEXT("Times New Roman"));
HGDIOBJ hbmpOld = SelectObject(hdc, hbmp);
HGDIOBJ hbrushOld = SelectObject(hdc, hbrush);
HGDIOBJ hpenOld = SelectObject(hdc, hpen);
HGDIOBJ hfontOld = SelectObject(hdc, hfont);
SetTextColor(hdc, Color::Black);
SetBkColor(hdc, Color::White);
SetBkMode(hdc, OPAQUE);
RECT rect={50,0,50,0};
FillRect(hdc, &rect, hbrush);
DrawText(hdc, "1", -1, &rect, DT_LEFT);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hbmp);
CloseClipboard();
getchar();
}
But after this code in clipboard i have only black square without symbol.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了颜色名称之外,您似乎没有使用 GDI+。我会使用 GDI
RGB
宏来代替:白色 =RGB(255,255,255)
,黑色 =RGB(0,0,0)
。您还将把所有选择的内容保留到 DC 中。在打开剪贴板之前,将所有旧对象重新选择回 DC。
You don't appear to be using GDI+ except for the color names. I'd use the GDI
RGB
macro instead: white =RGB(255,255,255)
, black =RGB(0,0,0)
.You're also leaving everything selected into the DC. Reselect all the old objects back into the DC before you open the clipboard.