0

We are rendering some rectangles to a SharpDx 2D panel, that all works fine. The clients have the ability to share the selected data to an image (to be able to post it somewhere). This process is done by drawing the elements on to a WIC.Bitmap and then copying that data into a System.Drawing.Bitmap. There is no way around doing this because the export code works solely on System.Drawing.Bitmaps and it cannot be changed as it affects way too many other parts of the project. The question is how can we get a high quality image from this transfer. as the image that we get is really pixely. Please see below example of what it looks like. enter image description here BTW: The random strokes in the image are supposed to be continuous lines

Below you will find the Conversion Code:

            int width = wicBitmap.Size.Width;
            int height = wicBitmap.Size.Height;
            System.Drawing.Bitmap gdiBitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            System.Drawing.Imaging.BitmapData gdiBitmapData = gdiBitmap.LockBits(
                new System.Drawing.Rectangle(0, 0, gdiBitmap.Width, gdiBitmap.Height),
                System.Drawing.Imaging.ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            int[] buffer = new int[width * height];
            wicBitmap.CopyPixels(buffer);
            System.Runtime.InteropServices.Marshal.Copy(buffer, 0, gdiBitmapData.Scan0, buffer.Length);

            gdiBitmap.UnlockBits(gdiBitmapData);

And here is how the WIC bitmap is created:

                    SharpDX.WIC.Bitmap bitmap = new SharpDX.WIC.Bitmap(factory, width, height, SharpDX.WIC.PixelFormat.Format32bppPBGRA, SharpDX.WIC.BitmapCreateCacheOption.CacheOnDemand);

                    _overrideRect = new RectangleF(0, 0, bitmap.Size.Width, bitmap.Size.Height);

                    RenderTargetProperties renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default,
                    new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied), 0, 0,
                    RenderTargetUsage.None,
                    FeatureLevel.Level_DEFAULT);
                    SharpDX.Direct2D1.Factory rtfactory = new Factory(FactoryType.SingleThreaded);
                    using (WicRenderTarget target = new WicRenderTarget(rtfactory, bitmap, renderTargetProperties) { Tag = bitmap })

What can we do to get this image to look clean and clear?

Maza
  • 1
  • 4
  • Are you sure your problem is in the conversion? I would expect `CopyPixels` to copy the raw pixel data, without any processing. I would suspect the original drawing, or possibly some alpha blending issue, more than the pixel copy. – JonasH Nov 08 '22 at 14:44
  • It's supposed to work, but do you have a more complete sample code? One that reproduces the problem. – Simon Mourier Nov 09 '22 at 06:12

0 Answers0