[quote=引用 23 楼 lingyun0 的回复:] 困扰了很久,终于解决了,亲测可用。谢谢。 painter->setRenderHints(QPainter::SmoothPixmapTransform);//消锯齿 后面使用drawPixmap绘图。 (蒙板图片设成圆的就可以画圆了,我是画的圆角) 基本逻辑: (1) painter->setRenderHints(QPainter::SmoothPixmapTransform);//消锯齿 (2) QBitmap maskImage("Resources/images/icon/ic_portrait_mask_90x90.png"); //蒙板图片 QSize iconSize = icon.size(); icon = icon.scaled(QSize(90,90)); icon.setMask(maskImage); (3) painter->drawPixmap(iconRect,icon); 蒙板图片:
困扰了很久,终于解决了,亲测可用。谢谢。 painter->setRenderHints(QPainter::SmoothPixmapTransform);//消锯齿 后面使用drawPixmap绘图。 (蒙板图片设成圆的就可以画圆了,我是画的圆角) 基本逻辑: (1) painter->setRenderHints(QPainter::SmoothPixmapTransform);//消锯齿 (2) QBitmap maskImage("Resources/images/icon/ic_portrait_mask_90x90.png"); //蒙板图片 QSize iconSize = icon.size(); icon = icon.scaled(QSize(90,90)); icon.setMask(maskImage); (3) painter->drawPixmap(iconRect,icon); 蒙板图片:
[quote=引用 17 楼 xsjcoder 的回复:] [quote=引用 16 楼 JiMoKuangXiangQu 的回复:] [quote=引用 15 楼 zhao4zhong1 的回复:] [quote=引用 13 楼 JiMoKuangXiangQu 的回复:] 可能需要 QPainter::SmoothPixmapTransform 特性或者 HighQualityAntialiasing 。
[quote=引用 16 楼 JiMoKuangXiangQu 的回复:] [quote=引用 15 楼 zhao4zhong1 的回复:] [quote=引用 13 楼 JiMoKuangXiangQu 的回复:] 可能需要 QPainter::SmoothPixmapTransform 特性或者 HighQualityAntialiasing 。
[quote=引用 15 楼 zhao4zhong1 的回复:] [quote=引用 13 楼 JiMoKuangXiangQu 的回复:] 可能需要 QPainter::SmoothPixmapTransform 特性或者 HighQualityAntialiasing 。
[quote=引用 13 楼 JiMoKuangXiangQu 的回复:] 可能需要 QPainter::SmoothPixmapTransform 特性或者 HighQualityAntialiasing 。
可能需要 QPainter::SmoothPixmapTransform 特性或者 HighQualityAntialiasing 。
[quote=引用 10 楼 JiMoKuangXiangQu 的回复:] QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); draw(&painter); 供参考。
QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); draw(&painter);
QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); draw(&painter); 供参考。
只是我不了解QT。 可能你不必放弃用QT自带的绘图功能。
#include <windows.h> #include <gdiplus.h> using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") VOID OnPaint(HDC hdc) { Graphics graphics(hdc); Pen pen(Color(255, 0, 0, 255)); FontFamily fontFamily(L"宋体"); Font font(&fontFamily, 12, FontStyleRegular, UnitPixel); PointF pointF1(30.0f, 60.0f),pointF2(230.0f, 60.0f); SolidBrush solidBrush(Color(255, 0, 0, 255)); StringFormat stringFormat; WCHAR testString[] = L"Hello034∠你好"; stringFormat.SetFormatFlags(StringFormatFlagsDirectionVertical); graphics.SetSmoothingMode(SmoothingModeDefault); graphics.DrawLine(&pen, 0, 0, 200, 100); graphics.DrawEllipse(&pen, 10, 10, 190, 90); graphics.SetTextRenderingHint(TextRenderingHintSystemDefault); graphics.DrawString(testString, -1, &font, pointF1, &stringFormat, &solidBrush); graphics.SetSmoothingMode(SmoothingModeHighQuality); graphics.DrawLine(&pen, 200, 0, 400, 100); graphics.DrawEllipse(&pen, 210, 10, 190, 90); graphics.SetTextRenderingHint(TextRenderingHintAntiAlias); graphics.DrawString(testString, -1, &font, pointF2, &stringFormat, &solidBrush); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch(message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); OnPaint(hdc); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) { HWND hWnd; MSG msg; WNDCLASS wndClass; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = TEXT("GettingStarted"); RegisterClass(&wndClass); hWnd = CreateWindow( TEXT("GettingStarted"), // window class name TEXT("Getting Started"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } GdiplusShutdown(gdiplusToken); return 0; }
24,860
社区成员
27,333
社区内容
加载中
试试用AI创作助手写篇文章吧