2011-04-16 22 views
0


我有一個控件(picturebox),我想在DirectX的幫助下繪製一個2D圖像。 我有一個顯示和精靈,它工作正常。如何在DirectX設備中縮放圖像?

// Some code here... 
_device = new Device(0, DeviceType.Hardware, pictureBox1, 
      CreateFlags.SoftwareVertexProcessing, 
presentParams); 
_sprite = new Sprite(_device);  
// ... 
_sprite.Draw(texture, textureSize, _center, position, Color.White); 

問題是紋理尺寸比picturebox大得多,我只是想找到適合它的方式。
我試圖設置device.Transform屬性,但它並不能幫助:

var transform = GetTransformationMatrix(textureSize.Width, textureSize.Height); 
_device.SetTransform(TransformType.Texture0, transform); 

這裏是GetTransform方法:

Matrix GetTransformationMatrix(float width, float height) 
{ 
    var scaleWidth = pictureBox1.Width /width ; 
    var scaleHeight = pictureBox1.Height/height; 
    var transform = new Matrix(); 
    transform.M11 = scaleWidth; 
    transform.M12 = 0; 
    transform.M21 = 0; 
    transform.M22 = scaleHeight; 
    return transform; 
} 

感謝您的任何解決方案||幫幫我。

回答

0

的解決方案是隻使用此:

var transformMatrix = Matrix.Scaling(scaleWidth, scaleHeight, 0.0F); 

代替手工製作方法。