I have an Direct2D demo that creates a GridPatternBitmapBrush then draws the grid pattern on a TForm in a paint method. How do you get the Direct2D GridPatternBitmapBrush to appear on a TcxImage.Canvas( DeveloperExpress TImage) insead of the form?
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;
You need to change the constructor of the d2dCanvas.
Currently it's
d2dCanvas := TDirect2DCanvas.Create(Handle);
which is passing the forms handle to create the canvas.
I don't have Delphi 2010 (Which it seems is shipped with required units for the demo) but I think
d2dCanvas := TDirect2DCanvas.Create(MyTcxImage.Canvas.Canvas, Rect(0,0, MyTcxImage.Width,MyTcxImage.Height));
should do the trick
You'll need to pass Canvas.Canvas to this constructor because the cx components (at least my version of) use a TcxCanvas which contains a TCanvas.
You may be able to pass the Window Handle of the TcxImage Control to the Direct2DCanvas constructor.
精彩评论