CesiumLanguageWriter.Advanced.CesiumFormattingHelper.DownloadUriIntoDataUri C# (CSharp) Method

DownloadUriIntoDataUri() public static method

Downloads and converts a remote resource URI into a data URI in the form data:<MimeType>;base64,<ImageData>, where <MimeType> is the MIME type of the specified resource, and <ImageData> is the data encoded as a Base 64 string.
public static DownloadUriIntoDataUri ( string uri ) : string
uri string The URI of the resource to convert.
return string
        public static string DownloadUriIntoDataUri(string uri)
        {
            if (uri.StartsWith("data:"))
                return uri;

            WebRequest request = WebRequest.Create(uri);
            HttpWebRequest httpWebRequest = request as HttpWebRequest;
            if (httpWebRequest != null)
            {
                httpWebRequest.UserAgent = "CesiumWriter";
            }

            using (WebResponse webResponse = request.GetResponse())
            using (Stream responseStream = webResponse.GetResponseStream())
            {
                string mimeType = webResponse.ContentType;
                return BuildDataUri(mimeType, responseStream);
            }
        }

Usage Example

        /// <summary>
        /// Resolves a URI, producing a new URI for inclusion in a CZML document.
        /// </summary>
        /// <param name="uri">The source URI.</param>
        /// <returns>A URI suitable for CZML.</returns>
        public string ResolveUri(string uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            LinkedListNode <CacheItem> node;

            if (m_dictionary.TryGetValue(uri, out node))
            {
                if (m_lruList.First != node)
                {
                    //move to front
                    m_lruList.Remove(node);
                    m_lruList.AddFirst(node);
                }
                return(node.Value.ResolvedUri);
            }

            //load image into data URI
            string resolvedUri = CesiumFormattingHelper.DownloadUriIntoDataUri(uri);

            AddUri(uri, resolvedUri);
            return(resolvedUri);
        }
All Usage Examples Of CesiumLanguageWriter.Advanced.CesiumFormattingHelper::DownloadUriIntoDataUri