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.
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?