Exemplo n.º 1
0
 public static byte[] Serialize(this IBinaryStorable item)
 {
     using (var ms = new MemoryStream())
     {
         var writer = new BinaryWriter(ms);
         item.Save(writer);
         return(ms.ToArray());
     }
 }
 private static string GetDominantColor(IBinaryStorable image, int quality, bool ignoreWhite)
 {
     using (var bitmap = new Bitmap(image.BinaryData.OpenRead()))
     {
         var colorThief    = new ColorThief();
         var dominantColor = colorThief.GetColor(bitmap, quality, ignoreWhite);
         return(dominantColor.Color.ToHexString());
     }
 }
Exemplo n.º 3
0
        /// <summary>Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. Gets the routed BLOB from the request.
        /// </summary>
        /// <remarks>The implementation returns IContentMedia.BinaryData.</remarks>
        /// <param name="httpContext">The HTTP context.</param>
        /// <returns>
        /// </returns>
        /// <exception cref="T:System.NotImplementedException">
        /// </exception>
        /// <exclude />
        protected override Blob GetBlob(HttpContextBase httpContext)
        {
            string customRouteData = httpContext.Request.RequestContext.GetCustomRouteData <string>(DownloadMediaRouter.DownloadSegment);

            if (!string.IsNullOrEmpty(customRouteData))
            {
                httpContext.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"; filename*=UTF-8''{1}", (object)customRouteData, (object)Uri.EscapeDataString(customRouteData)));
            }

            IBinaryStorable content = ServiceLocator.Current.GetInstance <IContentRouteHelper>().Content as IBinaryStorable;

            if (content == null)
            {
                return((Blob)null);
            }

            return(content.BinaryData);
        }