2014-01-12 95 views
0

我有一個程序,我試圖使用SlimDX和VB.net將Direct2D中的圖像渲染到四邊形上。通過BitmapBrush繪製位圖到SlimDX幾何(VB.NET)

程序從服務器獲取4個點的數組,這是一個四邊形,圖像應該放在上面。

的點(例如)是:

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 

...構造一個BitmapBrush時加載和位圖可以呈現精細,而是試圖渲染到四邊形的時候,我只得到(它似乎......)右下角的一部分。

供參考:這是我想要繪製圖像: http://i.imgur.com/Dt3iHQ3.png

這裏是我在嘗試使用(繪製圖像)的代碼。 R是點列表(參見上面),RenderBrush是從該圖像的20x30版本創建的BitmapBrush。

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 

在此先感謝您的幫助!

+0

我還不確定,畫筆似乎並沒有繪製... –

回答

0

我想通了。爲了讓它在幾何圖形上繪製,需要設置如下這樣的變換矩陣:

Matrix3x2.Multiply(Matrix3x2.Translation(Point_To_Move_To), Matrix3x2.Rotation(Rotation, Point_To_Rotate_Around))