   DirectDraw producing crappy graphics[C#]
  I have been working on a DirectDraw project in C#. Just so everyone knows, I do know that it is old and deprecated and using Direct3D would be better; I do like DirectDraw though because it is simpler to use. I have gotten everything setup and working fine, but when it renders it. It comes out with crappy graphics. I can't tell if it's when it renders it, or when it loads the surface. Here is my code; tell me if you find anything that could cause this:class DirectX    {   [DllImport("user32.dll")]   private static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle rect);   public Device Device;   public Surface BackBuffer;   public Surface PrimaryBuffer;   public List<Surface> surfaces;   private IntPtr Handle;   public DirectX(Control window, Control clipper)   {  try  { this.Device = new Device(); this.Device.SetCooperativeLevel(window, CooperativeLevelFlags.Normal); SurfaceDescription desc = new SurfaceDescription(); desc.SurfaceCaps.PrimarySurface = true; this.PrimaryBuffer = new Surface(desc, this.Device); this.PrimaryBuffer.Clipper = new Clipper(); this.PrimaryBuffer.Clipper.Window = clipper; this.Handle = clipper.Handle; desc.Clear(); desc.Width = window.Width; desc.Height = window.Height; desc.SurfaceCaps.OffScreenPlain = true; this.BackBuffer = new Surface(desc, this.Device); this.surfaces = new List<Surface>();  }  catch (DirectXException e)  { MessageBox.Show(e.ToString());  }   }   public bool RestoreSurfaces()   {  bool restore = this.Device.TestCooperativeLevel();  if (restore == true)  { this.Device.RestoreAllSurfaces(); //this.PrimaryBuffer.Restore(); return true;  }  else return false;   }   ~DirectX()   {  this.PrimaryBuffer.Dispose();  this.BackBuffer.Dispose();  foreach (Surface surface in surfaces)  { surface.Dispose();  }  this.Device.Dispose();   }   public Surface CreateSurface(int width, int height)   {  SurfaceDescription desc = new SurfaceDescription();  desc.SurfaceCaps.OffScreenPlain = true;  desc.Width = width;  desc.Height = height;  Surface surface = new Surface(new Bitmap(width, height), desc, this.Device);  surfaces.Add(surface);  return surface;   }   public Surface CreateSurface(Bitmap bitmap)   {  SurfaceDescription desc = new SurfaceDescription();  desc.SurfaceCaps.OffScreenPlain = true;  desc.Width = bitmap.Width;  desc.Height = bitmap.Height;  Surface surface = new Surface(bitmap, desc, this.Device);  surfaces.Add(surface);  return surface;   }   public Surface CreateSurface(string file)   {  SurfaceDescription desc = new SurfaceDescription();  desc.SurfaceCaps.OffScreenPlain = true;  Surface surface = new Surface(file, desc, this.Device);  surfaces.Add(surface);  return surface;   }   public void ColorFill(Color color)   {  BackBuffer.ColorFill(color);   }   public void Draw(int x, int y, Surface surface)   {  BackBuffer.DrawFast(x, y, surface, DrawFastFlags.DoNotWait | DrawFastFlags.SourceColorKey);   }   public void MakeTransparent(ref Surface surface, Color color)   {  ColorKey key = new ColorKey();  key.ColorSpaceHighValue = key.ColorSpaceLowValue = color.ToArgb();  surface.SetColorKey(ColorKeyFlags.SourceDraw, key);   }   public void Flip()   {  Rectangle rect = new Rectangle();  GetWindowRect(Handle, ref rect);  rect.Width -= rect.X;  rect.Height -= rect.Y;  PrimaryBuffer.Draw(rect, BackBuffer, DrawFlags.Wait);   }    }  Surface surface = Network.DirectX.CreateSurface("C:\\Users\\Addison\\Desktop\\tryme.bmp");  Network.DirectX.MakeTransparent(ref surface, Color.Black);  int x = 0, y = 0;  while (form.Created == true)  { DateTime now = DateTime.Now; Network.DirectX.ColorFill(Color.White); Network.DirectX.Draw(x, y, surface); Network.DirectX.Flip(); DateTime after = DateTime.Now; Console.WriteLine(after.Subtract(now).Milliseconds.ToString()); Application.DoEvents(); Thread.Sleep(1);  }Here is what it comes out as:http://img375.imageshack.us/i/ddrawfail.png/And here is what the picture should look like:http://img709.imageshack.us/i/tryme.png/   
  If you want the black border then don't set a color key:RemoveNetwork.DirectX.MakeTransparent(ref surface, Color.Black);;  The correct picture is 64x32 pixels, while the bad one seems to be 62x29 or something like that. My guess is that your BackBuffer surface is created with the size of the entire window, including borders, while it should only have the dimensions of the actual client-area. If your window is for example 800x600, the client area might be 780x570 or something like that, and your back-buffer will be shrunk to fit that area. So in this case your picture that is 64 pixels wide in the back-buffer, will display at 64*780/800 pixels on screen, which is about 62 pixels.Not sure what API you're using, but perhaps window.ClientRectangle can give you the correct size for the back-buffer, or there should be a similar property that works.   ;  Beautiful call, man. Right on the dot. Thanks for all the help, would've never guessed :P   