我有一个 Direct2D 演示,它创建一个 GridPatternBitmapBrush 然后在一个绘图方法中在一个 TForm 上绘制网格图案。如何让 Direct2D GridPatternBitmapBrush 出现在表单的 TcxImage.Canvas(DeveloperExpress TImage) 上?
procedure TFormAdvGeometries.Create_FRadialGradientBrush;
var
// aGradientStops: array of TD2D1GradientStop;
// aGradBrushProps: TD2D1RadialGradientBrushProperties;
// aGradStopsCollection: ID2D1GradientStopCollection;
gradColors: array of TColor;
begin
SetLength(gradColors, 3);
gradColors[0] := TColor($00D7FF); // Gold (D2D1Helper.h)
gradColors[1] := TColor($00A5FF); // Orange (D2D1Helper.h)
gradColors[2] := TColor($0045FF); // OrangeRed (D2D1Helper.h)
// this is a place-holder.
// Code below assumes equal spread for positions in gradient stops
FRadialGradientBrush := d2dCanvas.CreateBrush(
gradColors,
D2D1PointF(330, 330),
D2D1PointF(140, 140),
140,
140
);
end;
procedure TFormAdvGeometries.Create_FGridPatternBitmapBrush;
var
gridBrush: ID2D1SolidColorBrush;
bmpBrushProps: D2D1_BITMAP_BRUSH_PROPERTIES;
bitmapRenderTarget: ID2D1BitmapRenderTarget;
bmpSize: D2D_SIZE_F;
gridBitmap: ID2D1Bitmap;
begin
bmpSize.width := 10;
bmpSize.height := 10;
d2dCanvas.RenderTarget.CreateCompatibleRenderTarget(
@bmpSize, nil, nil, 0, bitmapRenderTarget);
bitmapRenderTarget.CreateSolidColorBrush(
D2D1ColorF(0.93, 0.94, 0.96, 1), nil, gridBrush);
bitmapRenderTarget.BeginDraw;
bitmapRenderTarget.FillRectangle(Rect(0, 0, 10, 1), gridBrush);
bitmapRenderTarget.FillRectangle(Rect(0, 0, 1, 10), gridBrush);
bitmapRenderTarget.EndDraw;
bitmapRenderTarget.GetBitmap(gridBitmap);
bmpBrushProps.extendModeX := D2D1_EXTEND_MODE_WRAP;
bmpBrushProps.extendModeY := D2D1_EXTEND_MODE_WRAP;
bmpBrushProps.interpolationMode := 0; // could be 1
d2dCanvas.RenderTarget.CreateBitmapBrush(
gridBitmap, @bmpBrushProps, nil, FGridPatternBitmapBrush);
end;
procedure TFormAdvGeometries.CreateDeviceResources;
begin
Create_FRadialGradientBrush;
Create_FGridPatternBitmapBrush;
end;
procedure TFormAdvGeometries.Paint;
var defMatrix: TD2DMatrix3x2F;
begin
inherited;
CreateDeviceResources;
d2dCanvas.BeginDraw;
try
d2dCanvas.RenderTarget.GetTransform (defMatrix);
// fill with white color the whole window
d2dCanvas.RenderTarget.Clear(D2D1ColorF(clWhite));
// fill canvas with little blue rectangles
d2dCanvas.Brush.Handle := FGridPatternBitmapBrush;
d2dCanvas.Rectangle(0, 0, ClientWidth + 50, ClientHeight + 50);
// reset standard transformation
d2dCanvas.RenderTarget.SetTransform (defMatrix);
finally
d2dCanvas.EndDraw;
end;
end;