driver.cpp
上传用户:oersted3
上传日期:2022-05-07
资源大小:281k
文件大小:4k
源码类别:

图形图像处理

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <math.h>
  5. #include "aaform.hpp"
  6. using namespace std;
  7. HBITMAP transbmp;
  8. BITMAP transbmpdat;
  9. #define TESTFUNC 0
  10. #define IMAGENAME "rose.bmp"
  11. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  12. {
  13.     switch (message)
  14.     {
  15.         case WM_PAINT:
  16.             {
  17.                 HDC ldc = CreateCompatibleDC(0);
  18.                 SelectObject(ldc, transbmp);
  19.                 HDC ddc = GetDC(hwnd);
  20.                 BitBlt(ddc, 0, 0, transbmpdat.bmWidth, transbmpdat.bmHeight, ldc, 0, 0, SRCCOPY);
  21.                 ReleaseDC(hwnd, ddc);
  22.                 DeleteDC(ldc);
  23.             }
  24.             break;
  25.         case WM_DESTROY:
  26.             PostQuitMessage (0);
  27.             break;
  28.     }
  29.     return DefWindowProc (hwnd, message, wParam, lParam);
  30. }
  31. bool callbackfunc(double percentdone)
  32. {
  33.     cout << (int)(percentdone * 1000) / 10.0 << "% Completed" << endl;
  34.     return false;
  35. }
  36. int main()
  37. {
  38. return WinMain(NULL, NULL, NULL, SW_SHOW);
  39. }
  40. int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
  41. {
  42.     //Load and rotate image
  43.     HBITMAP hsrcbmp = (HBITMAP)LoadImage(NULL, IMAGENAME, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
  44.     int starttime = GetTickCount();
  45.     vector<double> x;
  46.     vector<double> y;
  47.     //A variety of tests
  48.     if (TESTFUNC == 0)
  49.     {
  50.         x.push_back(200); y.push_back(30);
  51.         x.push_back(500); y.push_back(0.0);
  52.         x.push_back(300); y.push_back(500);
  53.         x.push_back(0); y.push_back(400);
  54.         transbmp = aaform::createtransform(hsrcbmp, x, y, callbackfunc, 0xFF00FF);
  55.     }
  56.     else if (TESTFUNC == 1)
  57.     {
  58.         transbmp = aaform::stretch(hsrcbmp, .7, .6, callbackfunc, 0xFFFFFF);
  59.     }
  60.     else if (TESTFUNC == 2)
  61.     {
  62.         transbmp = aaform::rotate(hsrcbmp, 37, callbackfunc, 0xFF00FF);
  63.     }
  64.     else if (TESTFUNC == 3)
  65.     {
  66.         transbmp = aaform::skewverticle(hsrcbmp, 37, callbackfunc, 0xFF00FF);
  67.     }
  68.     else if (TESTFUNC == 4)
  69.     {
  70.         transbmp = aaform::skewhorizontal(hsrcbmp, 37, callbackfunc, 0xFF00FF);
  71.     }
  72.     cout << "Transform completed in " << GetTickCount() - starttime << " milliseconds" << endl;    
  73.     DeleteObject(hsrcbmp);
  74.     //Get info on the image so we can create the right sized window and for drawing
  75.     GetObject(transbmp, sizeof(BITMAP), &transbmpdat);
  76.     //Standard windows code
  77.     HWND hwnd;
  78.     MSG messages;
  79.     WNDCLASSEX wincl;
  80.     wincl.hInstance = hThisInstance;
  81.     wincl.lpszClassName = "Rotator";
  82.     wincl.lpfnWndProc = WindowProcedure;
  83.     wincl.style = CS_DBLCLKS;
  84.     wincl.cbSize = sizeof (WNDCLASSEX);
  85.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  86.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  87.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  88.     wincl.lpszMenuName = NULL;
  89.     wincl.cbClsExtra = 0;
  90.     wincl.cbWndExtra = 0;
  91.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  92.     if (!RegisterClassEx (&wincl))
  93.         return 0;
  94.     hwnd = CreateWindowEx (0, "Rotator", "Rotation Example", WS_OVERLAPPEDWINDOW,  CW_USEDEFAULT,  CW_USEDEFAULT, 
  95.            transbmpdat.bmWidth + 8, transbmpdat.bmHeight + 34, HWND_DESKTOP, NULL, hThisInstance, NULL);    
  96.     ShowWindow (hwnd, nFunsterStil);
  97.     while (GetMessage (&messages, NULL, 0, 0))
  98.     {
  99.         TranslateMessage(&messages);
  100.         DispatchMessage(&messages);
  101.     }
  102.     return (int)messages.wParam;
  103. }