开发者

How do I scale image in DirectX device?

I have a control (picturebox), in which I want to draw an 2D image with the help of DirectX. I have a display and sprite, and it works fine.

 // 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);

The problem is that texture size is much larger than picturebox, and I just want to find the way to fit it there.

I tried to set device.Transform property but it doesn't help:

var transform = GetTransformationMatrix(textureSize.Width, textureSize.Height);
_device.SetTra开发者_运维知识库nsform(TransformType.Texture0, transform);

Here is GetTransform method:

 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;  
}

Thanks for any solution || help.


The solution was just to use this:

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

instead of hand-made method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜