首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

DirectDraw C# 入門攻略(三):Blt 限制繪製區域、Clipper 裁剪視窗邊界

     編輯:關於C語言

BMP 檔案載入與 BltFast

BMP 為 DIB 格式,標頭含調色盤資訊,dDDesc1 已設定無需重複。RECT 控制顯示區域。BltFast 參數指定螢幕座標與來源矩形:

dDsurface.BltFast(0, 0, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFASTFLAGS.DDBLTFAST_WAIT);

圖片超出 Form 區域,因 PrimarySurface 代表整個可見區域。

Blt 限制在視窗客戶區

dx.GetWindowRect(this.Handle.ToInt32(), ref rectSec);
dDsurface.Blt(ref rectSec, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFLAGS.DDBLT_WAIT);

圖片限制在 Form 區域,但標題列被覆蓋。

Clipper 裁剪視窗邊界

dDclipper = dDraw.CreateClipper(0);
dDclipper.SetHWnd(this.Handle.ToInt32());
dDsurface.SetClipper(dDclipper);

Clipper 依視窗控制代碼裁剪,正確保留標題列:

整理後完整 draw() 方法

private void draw()
{
    dDraw = dx.DirectDrawCreate("");
    DxVBLib.DirectDrawClipper dDclipper;
    dDraw.SetCoOperativeLevel(this.Handle.ToInt32(), DxVBLib.CONST_DDSCLFLAGS.DDSCL_NORMAL);
    DxVBLib.RECT rect, rectSec = new DxVBLib.RECT();
    DxVBLib.DirectDrawSurface7 dDsurface, dDsurfaceSec;
    DxVBLib.DDSURFACEDESC2 dDDesc = new DxVBLib.DDSURFACEDESC2(), dDDesc1 = new DxVBLib.DDSURFACEDESC2();
    dDDesc.lFlags = DxVBLib.CONST_DDSURFACEDESCFLAGS.DDSD_CAPS;
    dDDesc.ddsCaps.lCaps = DxVBLib.CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE;
    dDsurface = dDraw.CreateSurface(ref dDDesc);
    dDclipper = dDraw.CreateClipper(0);
    dDclipper.SetHWnd(this.Handle.ToInt32());
    dDsurface.SetClipper(dDclipper);
    dDsurfaceSec = dDraw.CreateSurfaceFromFile("c:\\3.bmp", ref dDDesc1);
    dx.GetWindowRect(this.Handle.ToInt32(), ref rectSec);
    rect.Top = 0; rect.Left = 0;
    rect.Right = dDDesc1.lWidth; rect.Bottom = dDDesc1.lHeight;
    dDsurface.Blt(ref rectSec, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFLAGS.DDBLT_WAIT);
}
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved