GDI+ 如何把一个图像画成梯形样子?

QSmile 2009-07-09 11:51:18
GDI+ 如何把一个图像画成梯形样子?GDI+ 如何把一个图像画成梯形样子?
...全文
555 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
QSmile 2009-07-14
  • 打赏
  • 举报
回复
to: chehw
代码不行呢?
chehw 2009-07-14
  • 打赏
  • 举报
回复
我测试过了, 可以

// Demo.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Demo.h"
#include <math.h>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DEMO, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMO));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DEMO));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DEMO);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
void WndProc_OnPaint(HWND hWnd, HDC hdc);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
WndProc_OnPaint(hWnd, hdc);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}

void WndProc_OnPaint(HWND hWnd, HDC hdc)
{
static HDC hMemDC=CreateCompatibleDC(hdc);
static HBITMAP hMemBitmap=CreateCompatibleBitmap(hdc, 200, 200);
HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap);
PatBlt(hMemDC, 0, 0, 200, 200, BLACKNESS);

Rectangle(hdc, 0, 100, 400, 300);

SetGraphicsMode(hdc, GM_ADVANCED);
XFORM xForm;
xForm.eM11=1.0;
xForm.eM12=0.0;
xForm.eM21=0.0;
xForm.eM22=1.0;
xForm.eDx=0.0;
xForm.eDy=0.0;

XFORM xForm2;
CopyMemory(&xForm2, &xForm, sizeof(XFORM));

int i;

SetWindowOrgEx(hdc, -200, -100, NULL);
for(i=0;i<200;i++)
{
xForm.eM11=(200.0+i)/200.0;
xForm.eDx=0;
SetWorldTransform(hdc, &xForm);
BitBlt(hdc, -100, i, 200, 1, hMemDC, 0, 0, SRCCOPY);
}


}
BruceLin2008 2009-07-13
  • 打赏
  • 举报
回复
ding
sailtoyouSCU 2009-07-13
  • 打赏
  • 举报
回复
matix 错切变换
realizz 2009-07-13
  • 打赏
  • 举报
回复
DrawLine 画4条边,如何?
chehw 2009-07-13
  • 打赏
  • 举报
回复
优化一下:

SetWindowOrgEx(hdc, -200, -100, NULL);
for(i=0;i<200;i++)
{
xForm.eM11=(200.0+i)/200.0;

SetWorldTransform(hdc, &xForm);
BitBlt(hdc, -100, i, 200, 1, hMemDC, 0, 0, SRCCOPY);
}
chehw 2009-07-13
  • 打赏
  • 举报
回复
GDI示例: 将200*200矩形变换为上底200下底400的梯形

SetGraphicsMode(hdc, GM_ADVANCED);

XFORM xForm;
xForm.eM11=1.0;
xForm.eM12=0.0;
xForm.eM21=0.0;
xForm.eM22=1.0;
xForm.eDx=0.0;
xForm.eDy=0.0;

SetWindowOrgEx(hdc, -100, -100, NULL);
for(i=0;i<200;i++) // i<梯形高度
{
xForm.eM11=(200.0+i)/200.0;
xForm.eDx=-i/2;
SetWorldTransform(hdc, &xForm);
BitBlt(hdc, 0, i, 200, 1, hMemDC, 0, 0, SRCCOPY);
}
tkminigame 2009-07-10
  • 打赏
  • 举报
回复
准备个缓存,把图像进行单行的缩放变换,再叠起来就是梯形了。
QSmile 2009-07-10
  • 打赏
  • 举报
回复
GDI+ 可以指定变换矩形进行变换

可以旋转,平行四边形变换都行,但现在要画成梯形的
geqipeng 2009-07-10
  • 打赏
  • 举报
回复
梯形不就是输入上下边长,输入某个点的位置。。。然后画四条线么。。。-_-
jtujtujtu 2009-07-10
  • 打赏
  • 举报
回复
自己按行缩放
很容易实现
Ryanwen 2009-07-09
  • 打赏
  • 举报
回复
???GDI能指定样子吗? 这个得自己实现

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧