Direct2D (11) : 画刷之 ID2D1LinearGradientBrush
生活随笔
收集整理的這篇文章主要介紹了
Direct2D (11) : 画刷之 ID2D1LinearGradientBrush
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
TDirect2DCanvas.Brush 的類型是 TDirect2DBrush,它和 GDI 的 TBrush 的區別主要有兩點:
1、只保留了 TBrush.Style 中的 bsSolid、bsClear 選項,棄用了:bsHorizontal、bsVertical、bsFDiagonal、bsBDiagonal、bsCross、bsDiagCross。
2、其 Handle 屬性是 Direct2D 中的 ID2D1Brush。
Direct2D 提供有四種畫刷: ID2D1SolidColorBrush //純色畫刷;TDirect2DBrush 默認使用了它 ID2D1LinearGradientBrush //線性漸變畫刷 ID2D1RadialGradientBrush //放射漸變畫刷 ID2D1BitmapBrush //位圖畫刷ID2D1Brush //是它們的父接口,它提供了透明色和 2D 變換的基礎能力。{相關方法} TDirect2DCanvas.RenderTarget.CreateSolidColorBrush(); //建立純色畫刷 TDirect2DCanvas.RenderTarget.CreateLinearGradientBrush(); //建立線性漸變畫刷 TDirect2DCanvas.RenderTarget.CreateRadialGradientBrush(); //建立放射漸變畫刷 TDirect2DCanvas.RenderTarget.CreateBitmapBrush(); //建立位圖畫刷TDirect2DCanvas.RenderTarget.CreateGradientStopCollection(); //建立畫刷需要的 ID2D1GradientStopCollection 對象//ID2D1GradientStopCollection 中包含漸變需要的顏色及位置數組和位圖排列規則參數等
ID2D1LinearGradientBrush : 線性漸變畫刷
{建立函數} function CreateLinearGradientBrush(const linearGradientBrushProperties: TD2D1LinearGradientBrushProperties; //描述漸變軸的結構體brushProperties: PD2D1BrushProperties; //描述透明度及 2D 變換的結構指針gradientStopCollection: ID2D1GradientStopCollection; //通過該接口傳遞 TD2D1GradientStop 結構(顏色及位置)的數組out linearGradientBrush: ID2D1LinearGradientBrush //輸出建立的對象 ): HResult; stdcall;{描述漸變軸的結構體} TD2D1LinearGradientBrushProperties = recordstartPoint: D2D1_POINT_2F;endPoint: D2D1_POINT_2F; end; {描述透明度及 2D 變換的結構體} TD2D1BrushProperties = recordopacity: Single;transform: D2D1_MATRIX_3X2_F; end; {描述位置與顏色的結構體} TD2D1GradientStop = recordposition: Single;color: D2D1_COLOR_F; end;
測試代碼:
uses Direct2D, D2D1;procedure TForm1.FormPaint(Sender: TObject); varcvs: TDirect2DCanvas;iBrush: ID2D1LinearGradientBrush;R: TRect;rLinear: TD2D1LinearGradientBrushProperties;arrGradientStop: array[0..2] of TD2D1GradientStop;iGradientStops: ID2D1GradientStopCollection; begincvs := TDirect2DCanvas.Create(Canvas, ClientRect);R := ClientRect;InflateRect(R, -ClientWidth div 6, -ClientHeight div 6);{對角線軸}rLinear.startPoint := D2D1PointF(R.Left, R.Top);rLinear.endPoint := D2D1PointF(R.Right, R.Bottom);{橫向軸} // rLinear.startPoint := D2D1PointF(R.Left, ClientHeight / 2); // rLinear.endPoint := D2D1PointF(R.Right, ClientHeight / 2);arrGradientStop[0].position := 0.0;arrGradientStop[0].color := D2D1ColorF(clRed);arrGradientStop[1].position := 0.5;arrGradientStop[1].color := D2D1ColorF(clYellow);arrGradientStop[2].position := 1.0;arrGradientStop[2].color := D2D1ColorF(clGreen);cvs.RenderTarget.CreateGradientStopCollection(@arrGradientStop[0], Length(arrGradientStop), D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, iGradientStops);cvs.RenderTarget.CreateLinearGradientBrush(rLinear, nil, iGradientStops, iBrush);cvs.Brush.Handle := iBrush;cvs.BeginDraw;cvs.Rectangle(R);cvs.EndDraw;cvs.Free; end;procedure TForm1.FormResize(Sender: TObject); beginRepaint; end;
效果圖:
總結
以上是生活随笔為你收集整理的Direct2D (11) : 画刷之 ID2D1LinearGradientBrush的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: App-V 4.6 SP1系列之五包加速
- 下一篇: .Net应该学什么怎么学(三)