Beispiel #1
0
        private SlimDX.Direct2D.Bitmap loadBitmap(Bitmap drawingBitmap)
        {
            SlimDX.Direct2D.Bitmap result = null;

            if (drawingBitmap == null)
            {
                return(null);
            }

            if (gr.Contains(drawingBitmap))
            {
                return(gb[gr.IndexOf(drawingBitmap)]);
            }
            else
            {
                gr.Add(drawingBitmap);
            }

            //Lock the gdi resource
            BitmapData drawingBitmapData = drawingBitmap.LockBits(
                new Rectangle(0, 0, drawingBitmap.Width, drawingBitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);

            //Prepare loading the image from gdi resource
            SlimDX.DataStream dataStream = new SlimDX.DataStream(drawingBitmapData.Scan0, drawingBitmapData.Stride * drawingBitmapData.Height, true, false);
            SlimDX.Direct2D.BitmapProperties properties = new SlimDX.Direct2D.BitmapProperties();
            properties.PixelFormat = new SlimDX.Direct2D.PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, SlimDX.Direct2D.AlphaMode.Premultiplied);
            //Load the image from the gdi resource
            result = new SlimDX.Direct2D.Bitmap(renderTarget, new Size(drawingBitmap.Width, drawingBitmap.Height), dataStream, drawingBitmapData.Stride, properties);

            //Unlock the gdi resource
            drawingBitmap.UnlockBits(drawingBitmapData);
            gb.Add(result);
            return(result);
        }
        private SlimDX.Direct2D.Bitmap loadBitmap(Bitmap drawingBitmap)
        {
            SlimDX.Direct2D.Bitmap result = null;

            if (drawingBitmap == null)
                return null;

            if (gr.Contains(drawingBitmap))
                return gb[gr.IndexOf(drawingBitmap)];
            else
                gr.Add(drawingBitmap);

            //Lock the gdi resource
            BitmapData drawingBitmapData = drawingBitmap.LockBits(
            new Rectangle(0, 0, drawingBitmap.Width, drawingBitmap.Height),
            ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);

            //Prepare loading the image from gdi resource
            SlimDX.DataStream dataStream = new SlimDX.DataStream(drawingBitmapData.Scan0, drawingBitmapData.Stride * drawingBitmapData.Height, true, false);
            SlimDX.Direct2D.BitmapProperties properties = new SlimDX.Direct2D.BitmapProperties();
            properties.PixelFormat = new SlimDX.Direct2D.PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, SlimDX.Direct2D.AlphaMode.Premultiplied);
            //Load the image from the gdi resource
            result = new SlimDX.Direct2D.Bitmap(renderTarget, new Size(drawingBitmap.Width, drawingBitmap.Height), dataStream, drawingBitmapData.Stride, properties);

            //Unlock the gdi resource
            drawingBitmap.UnlockBits(drawingBitmapData);
            gb.Add(result);
            return result;
        }