从SharePoint下载图像会降低图像质量

时间:2018-07-03 16:54:50

标签: c# asp.net-mvc

我正在同步SharePoint用户配置文件中的图像,并将其保存在数据库中。图像以VarBinary(MAX)的形式保存在DB中。 SharePoint中的图像看起来非常清晰。保存到数据库中后,我们在Web应用程序中显示消息。问题是,即使SharePoint配置文件图像显示得非常清晰,但Web应用程序图像却模糊了。 关于如何改善消息质量(如减少模糊)的任何建议?

以下显示了我们如何从SharePoint获取图像:-

private byte[] GetImageData(ClientContext context, string pictureUrl)
{
            //if (this.fedauthCookieContainer == null)
            //{
                Uri webUri = new Uri(pictureUrl);
                var authCookie = this.GetCredentials().GetAuthenticationCookie(webUri);
                var fedAuthString = authCookie.TrimStart("SPOIDCRL=".ToCharArray());
                var cookieContainer = new CookieContainer();
                cookieContainer.Add(webUri, new Cookie("SPOIDCRL", fedAuthString));
                this.fedauthCookieContainer = cookieContainer;
            //}
            using (HttpClientHandler handler = new HttpClientHandler())
            {
                handler.CookieContainer = this.fedauthCookieContainer;
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
                    //client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");

                    return client.GetByteArrayAsync(pictureUrl).Result;
                }
            }
        }

然后将SharePoint中的图像保存到数据库中之后,我们将其显示在Web应用程序中。以下代码显示了我们如何从数据库中获取图像。

[HttpGet]
        public async Task<HttpResponseMessage> Image(string email)
        {
            string mediaType = "image/jpeg";
            HttpResponseMessage file = this.File(this.GetDefaultHeadshotImage(), mediaType);
            var imageData = await this.profileService.GetProfileImage(email);
            if (imageData != null)
            {
                file = this.File(imageData, mediaType);
            }
            return file;
        }

这是我们在网络应用中显示图像的方式:-

<div class="widget-profile-user-image" data-bind="style: { backgroundImage: 'url(\'' + imageUrl() + '\')' }" style="background-image: url(&quot;/home/PDSPortal/api/Profile/Image?email=XYZ.ABC-LMN@am.jll.com&quot;);">
            <div class="widget-profile-achieverStatus" data-bind="css:  achieverStatusCss, visible: achieverStatus() != 'None'" style="display: none;">
                <div class="text" data-bind="text:  achieverStatus">None</div>
                <div class="arrow"></div>
            </div>
        </div>

0 个答案:

没有答案