public static byte[] ToEncodedBuffer(this Visual visual, ImageFormat preferredFormat, int qualityLevel = 95)
        {
            RenderTargetBitmap renderTargetBitmap = visual.ToRenderedBitmap();

            byte[] buffer = renderTargetBitmap.ToEncodedBuffer(preferredFormat, qualityLevel);
            // For some Reason, RenderTargetBitmap Resources are released very late.. this extension method solves Memory Leaks
            return(buffer);
        }