home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Images, Bitmaps, and Metafiles / Using Interpolation Mode to Control Image Quality During Scaling / GDITEST46.dpr
Encoding:
Text File  |  2003-10-15  |  3.8 KB  |  131 lines

  1. program GDITEST46;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   image: TGPImage;
  14.   width, height: UINT;
  15. begin
  16.   graphics := TGPGraphics.Create(DC);
  17.  
  18.   image:= TGPImage.Create('..\..\Media\GrapeBunch.bmp');
  19.   width  := image.GetWidth;
  20.   height := image.GetHeight;
  21.  
  22.   // Draw the image with no shrinking or stretching.
  23.   graphics.DrawImage(
  24.     image,
  25.     MakeRect(10, 10, width, height),  // destination rectangle
  26.     0, 0,        // upper-left corner of source rectangle
  27.     width,       // width of source rectangle
  28.     height,      // height of source rectangle
  29.     UnitPixel);
  30.  
  31.   // Shrink the image using low-quality interpolation.
  32.   graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);
  33.   graphics.DrawImage(
  34.     image,
  35.     MakeRect(10, 250, 0.6*width, 0.6*height),  // destination rectangle
  36.     0, 0,        // upper-left corner of source rectangle
  37.     width,       // width of source rectangle
  38.     height,      // height of source rectangle
  39.     UnitPixel);
  40.  
  41.   // Shrink the image using medium-quality interpolation.
  42.   graphics.SetInterpolationMode(InterpolationModeHighQualityBilinear);
  43.   graphics.DrawImage(
  44.     image,
  45.     MakeRect(150, 250, 0.6 * width, 0.6 * height),  // destination rectangle
  46.     0, 0,        // upper-left corner of source rectangle
  47.     width,       // width of source rectangle
  48.     height,      // height of source rectangle
  49.     UnitPixel);
  50.  
  51.   // Shrink the image using high-quality interpolation.
  52.   graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  53.   graphics.DrawImage(
  54.     image,
  55.     MakeRect(290, 250, 0.6 * width, 0.6 * height),  // destination rectangle
  56.     0, 0,        // upper-left corner of source rectangle
  57.     width,       // width of source rectangle
  58.     height,      // height of source rectangle
  59.     UnitPixel);
  60.  
  61.   image.Free;
  62.   graphics.Free;
  63. end;
  64.  
  65.  
  66. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  67. var
  68.   Handle: HDC;
  69.   ps: PAINTSTRUCT;
  70. begin
  71.   case message of
  72.     WM_PAINT:
  73.       begin
  74.         Handle := BeginPaint(Wnd, ps);
  75.         OnPaint(Handle);
  76.         EndPaint(Wnd, ps);
  77.         result := 0;
  78.       end;
  79.  
  80.     WM_DESTROY:
  81.       begin
  82.         PostQuitMessage(0);
  83.         result := 0;
  84.       end;
  85.  
  86.    else
  87.       result := DefWindowProc(Wnd, message, wParam, lParam);
  88.    end;
  89. end;
  90.  
  91. var
  92.   hWnd     : THandle;
  93.   Msg      : TMsg;
  94.   wndClass : TWndClass;
  95. begin
  96.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  97.    wndClass.lpfnWndProc    := @WndProc;
  98.    wndClass.cbClsExtra     := 0;
  99.    wndClass.cbWndExtra     := 0;
  100.    wndClass.hInstance      := hInstance;
  101.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  102.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  103.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  104.    wndClass.lpszMenuName   := nil;
  105.    wndClass.lpszClassName  := 'GettingStarted';
  106.  
  107.    RegisterClass(wndClass);
  108.  
  109.    hWnd := CreateWindow(
  110.       'GettingStarted',       // window class name
  111.       'Using Interpolation Mode to Control Image Quality During Scaling',      // window caption
  112.       WS_OVERLAPPEDWINDOW,    // window style
  113.       Integer(CW_USEDEFAULT), // initial x position
  114.       Integer(CW_USEDEFAULT), // initial y position
  115.       Integer(CW_USEDEFAULT), // initial x size
  116.       Integer(CW_USEDEFAULT), // initial y size
  117.       0,                      // parent window handle
  118.       0,                      // window menu handle
  119.       hInstance,              // program instance handle
  120.       nil);                   // creation parameters
  121.  
  122.    ShowWindow(hWnd, SW_SHOW);
  123.    UpdateWindow(hWnd);
  124.  
  125.    while(GetMessage(msg, 0, 0, 0)) do
  126.    begin
  127.       TranslateMessage(msg);
  128.       DispatchMessage(msg);
  129.    end;
  130. end.
  131.