Search code examples
c#graphicsbitmapdirect2dsharpdx

SharpDX Bitmaps


I've been looking around the internet for a while, and I can't seem to find the answer I've been looking for. So what I intend to do with bitmaps is I want to draw them onto the window, and be able properly resize them whenever. Any help would be appreciated!


Solution

  • For those of you who do not know, you can use matrices to translate, resize, and rotate. Here's how to do it. Also be sure to change the Matrix for the RenderTarget before you draw the actual object.

    Vector2

    RenderTarget.Transform

    RenderTarget.DrawBitmap

    Matrix.Transformation2D

    Vector2 center = new Vector2(bitmap.Size.Width / 2, bitmap.Size.Height / 2);
    renderTarget.Transform = Matrix.Transformation2D(center, 0f, new Vector2(width / bitmap.Size.Width, height / bitmap.Size.Height), center, MathHelper.ToRads(rotation), new Vector2(x - center.X, y - center.Y));
    renderTarget.DrawBitmap(bitmap, 1f, BitmapInterpolationMode.NearestNeighbor);
    renderTarget.Transform = Matrix.Transformation2D(Vector2.Zero, 0f, new Vector2(1f, 1f), Vector2.Zero, MathHelper.ToRads(0), Vector2.Zero);