Exemple #1
0
        public void DrawByte(byte[] bytes)
        {
            //System.Drawing.Graphics graphics = this.CreateGraphics();
            //graphics.DrawImage(bmp, 10, 10);


            /*d2dContext.Target = d2dTarget;
             * d2dContext.BeginDraw();
             * SolidColorBrush solidBrush = new SolidColorBrush(d2dContext, SharpDX.Color.Coral);
             * d2dContext.FillRectangle(new SharpDX.RectangleF(50, 50, 200, 200), solidBrush);*/

            //d2dTarget.CopyFromBitmap();
            //d2dContex

            d2dContext.Target = d2dTarget;
            d2dContext.BeginDraw();
            //d2dContext.
            //SolidColorBrush solidBrush = new SolidColorBrush(d2dContext, SharpDX.Color.Coral);
            //d2dContext.FillRectangle(new SharpDX.RectangleF(50, 50, 200, 200), solidBrush);

            //SharpDX.Rectangle rect = new SharpDX.Rectangle(0, 0, dWidth, dHeight);
            //d2dTarget.CopyFromMemory(bytes, dWidth * 4, rect);
            SharpDX.Rectangle rect = new SharpDX.Rectangle(0, 0, RenderWidth(), RenderHeight());
            d2dTarget.CopyFromMemory(bytes, RenderWidth() * 4, rect);

            //BitmapProperties bp = new BitmapProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied));
            //int stride = bmp.Width * sizeof(int);
            //SharpDX.Direct2D1.Bitmap newBMP = Texture2D.FromStream<Texture2D>()

            /*using (SharpDX.DataStream tempStream = new SharpDX.DataStream(bmp.Height * stride, false, true))
             * {
             *  for (int y = 0; y < bmp.Height; y++)
             *  {
             *      for (int x = 0; x < bmp.Width; x++)
             *      {
             *          System.Drawing.Color c = bmp.GetPixel(x, y);
             *          int a = c.A;
             *          int r = (c.R * a) / 255;
             *          int g = (c.G * a) / 255;
             *          int b = (c.B * a) / 255;
             *          int bgra = b | (g << 8) | (r << 16) | (a << 24);
             *          tempStream.Write(bgra);
             *      }
             *  }
             *
             *  //d2dRenderTarget.BeginDraw();
             *  //newBMP = new SharpDX.Direct2D1.Bitmap(d2dRenderTarget, new Size2(bmp.Width, bmp.Height), tempStream, stride, bp);
             *  //d2dRenderTarget.EndDraw();
             * }*/


            //rect, 1.0f, SharpDX.Direct2D1.InterpolationMode.Linear
            //SharpDX.Mathematics.Interop.RawRectangleF rect = new SharpDX.Mathematics.Interop.RawRectangleF(50, 50, dWidth + 50, dHeight + 50);
            //d2dContext.DrawBitmap(bmp, rect, 1.0f, SharpDX.Direct2D1.InterpolationMode.Linear);
            //d2dContext.DrawBitmap(bmp, 1.0f, SharpDX.Direct2D1.InterpolationMode.Linear);
            d2dContext.EndDraw();

            //newBMP.Dispose();
        }
        public void DrawBytes(byte[] bytes)
        {
            d2dContext.Target = d2dTarget;
            d2dContext.BeginDraw();

            SharpDX.Rectangle rect = new SharpDX.Rectangle(0, 0, RenderWidth, RenderHeight);
            d2dTarget.CopyFromMemory(bytes, RenderWidth * 4, rect);

            d2dContext.EndDraw();
        }