fork(2) download
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using SlimDX;
  5. using SlimDX.Windows;
  6. using SlimDX.Direct2D;
  7.  
  8. namespace Direct2DSample
  9. {
  10. static class Program
  11. {
  12. public static int x { get; set; }
  13.  
  14. [STAThread]
  15. static void Main()
  16. {
  17. var form = new RenderForm("SlimDX - Direct2D Sample");
  18. var factory = new Factory();
  19.  
  20. var target = new WindowRenderTarget(factory, new WindowRenderTargetProperties()
  21. {
  22. Handle = form.Handle,
  23. PixelSize = form.ClientSize
  24. });
  25.  
  26. var bitmap = CreateBitmap(target, "png.png");
  27.  
  28. MessagePump.Run(form, () =>
  29. {
  30. target.BeginDraw();
  31. target.Clear();
  32. x++;
  33. //絵が右のほうに動いていく。
  34. //自分でスレッドスリープとかしなくても、適度なfpsで動く。
  35. target.DrawBitmap(bitmap, new Rectangle(x, 0, 20, 20));
  36.  
  37. target.EndDraw();
  38. });
  39.  
  40. foreach (var item in ObjectTable.Objects)
  41. item.Dispose();
  42. }
  43.  
  44. public static SlimDX.Direct2D.Bitmap CreateBitmap(RenderTarget target, string filename)
  45. {
  46. var srcBitmap = new System.Drawing.Bitmap(filename);
  47.  
  48. var bitmapData = srcBitmap.LockBits(
  49. new Rectangle(0, 0, srcBitmap.Width, srcBitmap.Height),
  50. System.Drawing.Imaging.ImageLockMode.ReadOnly,
  51. System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
  52.  
  53. var stream = new DataStream(bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, true, false);
  54.  
  55. var properties = new BitmapProperties()
  56. {
  57. PixelFormat = new PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
  58. };
  59. var bitmap = new SlimDX.Direct2D.Bitmap(target, srcBitmap.Size, stream, bitmapData.Stride, properties);
  60.  
  61. srcBitmap.UnlockBits(bitmapData);
  62.  
  63. return bitmap;
  64. }
  65. }
  66. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(3,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(4,7): error CS0246: The type or namespace name `SlimDX' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(5,7): error CS0246: The type or namespace name `SlimDX' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(6,7): error CS0246: The type or namespace name `SlimDX' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(3,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(4,7): error CS0246: The type or namespace name `SlimDX' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(5,7): error CS0246: The type or namespace name `SlimDX' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(6,7): error CS0246: The type or namespace name `SlimDX' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 10 error(s), 0 warnings
stdout
Standard output is empty