Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I just started C# recently and I've been wanting to display a simple .bmp image on the window. I have managed to do this already but the size of the image is modified and made big when rendered :S, any way to specify the dimensions and also area of the image(frames)?

 

here is my current code:

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

class WinForm : Form
{
   public Device device;
   public PresentParameters presentParams;
   public Texture texture;

   WinForm()
   {
       this.Text = "DirectX Project";
       this.Width = 600;
       this.Height = 200;
       this.Show();
   }

   public static void Main()
   {
       Console.WriteLine("Program Executed");

       using (WinForm form = new WinForm())
       {
           form.InitializeGraphics();
           Application.Run(form);
       }
   }

   public void InitializeGraphics()
   {
       presentParams = new PresentParameters();
       presentParams.Windowed = true;
       presentParams.SwapEffect = SwapEffect.Discard;

       device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);

       texture = TextureLoader.FromFile(device, "image.bmp");
   }

   protected override void OnPaint(PaintEventArgs e)
   {
       Render();
   }

   public void Render()
   {
       device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
       device.BeginScene();

       using (Sprite s = new Sprite(device))
       {
           s.Begin(SpriteFlags.AlphaBlend);
           s.Draw2D(texture, new Point(0, 0), 0f, new Point(0, 0), Color.White);
           s.End();
       }

       device.EndScene();
       device.Present();
   }
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...