Question

I have a program where I am attempting to render an image in Direct2D onto a quadrilateral using SlimDX and VB.net.

The program gets an array of 4 points from a server, which are a quadrilateral, where the image should be rendered onto.

The points (For example) are:

points(0) = 20,10 <--Top left, where the geometry starts from
points(1) = 40,10 <-- Top right
points(2) = 40,40 <-- Bottom right
points(3) = 20,40 <-- Bottom left

...A BitmapBrush is constructed when loading and the Bitmap can be rendered fine, but when trying to render onto the quadrilateral, I only get (it seems...) some part the bottom right corner.

For reference: Here is the image I'm trying to draw: http://i.imgur.com/Dt3iHQ3.png

And here is the code that I'm trying to use (for drawing the image). R is the point list (see above) and RenderBrush is a BitmapBrush created from a 20x30 version of that image.

Private Sub DrawPoly(R() As PointF, ByRef RenderBrush As SlimDX.Direct2D.BitmapBrush)
    'Create the geometry
    Dim Path As PathGeometry
    Path = New PathGeometry(factoryD2D)
    Console.Clear()
    'Get a handle to the Geometry
    Dim Geometry = Path.Open()
    'Set UP Geometry
    Geometry.BeginFigure(R(0), FigureBegin.Filled)
    Geometry.AddLines(R)
    Geometry.EndFigure(FigureEnd.Closed)
    Geometry.Close()

    'Render
    D2DRenderTarget.FillGeometry(Path, RenderBrush)
    'and GC
    Geometry.Dispose()
    Path.Dispose()
End Sub

Thanks in advance for your help!

Was it helpful?

Solution

I figured it out. To get it to draw onto the geometry, you need to set up a transformation matrix like so:

Matrix3x2.Multiply(Matrix3x2.Translation(Point_To_Move_To), Matrix3x2.Rotation(Rotation, Point_To_Rotate_Around))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top