DataToDataUri() public static method

Create a data URI (according to RFC 2397).
public static DataToDataUri ( byte pbData, string strMimeType ) : string
pbData byte Data to encode.
strMimeType string Optional MIME type. If null, /// an appropriate type is used.
return string
Beispiel #1
0
        internal static string ImageToDataUri(Image img)
        {
            if (img == null)
            {
                Debug.Assert(false); return(string.Empty);
            }

            byte[] pb = null;
            using (MemoryStream ms = new MemoryStream())
            {
#if NETSTANDARD2_0
                var encoded = img.Encode();

                // get a stream over the encoded data
                Stream stream = encoded.AsStream();
                stream.CopyTo(ms);
                //img.Save(Splat.CompressedBitmapFormat.Png, 80, ms);
#else
                img.Save(ms, ImageFormat.Png);
#endif
                pb = ms.ToArray();
            }

            return(StrUtil.DataToDataUri(pb, "image/png"));
        }
Beispiel #2
0
        internal static string ImageToDataUri(Image img)
        {
            if (img == null)
            {
                Debug.Assert(false); return(string.Empty);
            }

            byte[] pb = null;
#if KeePassUWP
            var bitmap = new Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap();
            bitmap.RenderAsync(img).GetResults();
            var pixelBuffer = bitmap.GetPixelsAsync().GetResults();
            pb = new byte[pixelBuffer.Length];
            var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(pixelBuffer);
            dataReader.ReadBytes(pb);
            dataReader.Dispose();
#else
            using (MemoryStream ms = new MemoryStream())
            {
                img.Save(ms, ImageFormat.Png);
                pb = ms.ToArray();
            }
#endif

            return(StrUtil.DataToDataUri(pb, "image/png"));
        }
        internal static string ImageToDataUri(Image img)
        {
            if (img == null)
            {
                Debug.Assert(false); return(string.Empty);
            }

            byte[] pb = null;
            using (MemoryStream ms = new MemoryStream())
            {
                img.Save(ms, ImageFormat.Png);
                pb = ms.ToArray();
            }

            return(StrUtil.DataToDataUri(pb, "image/png"));
        }