我有一个控件(图片框),我想在DirectX的帮助下绘制一个2D图像。
我有一个显示和精灵,它工作正常。
// 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);
问题是纹理尺寸比图片框大得多,我只是想找到适合它的方法。
我试图设置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 :(得分:0)
解决方案就是使用它:
var transformMatrix = Matrix.Scaling(scaleWidth, scaleHeight, 0.0F);
而不是手工制作的方法。