• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# WebImage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中WebImage的典型用法代码示例。如果您正苦于以下问题:C# WebImage类的具体用法?C# WebImage怎么用?C# WebImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebImage类属于命名空间,在下文中一共展示了WebImage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: LoadImageFromWeb

        protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage))
                return false;
            HttpRequest httpRequest = new HttpRequest { Url = webImage.Url };
            string file = _urlCache.GetUrlSubPath(httpRequest);
            if (subDirectory != null)
                file = zPath.Combine(subDirectory, file);
            string path = zPath.Combine(_urlCache.CacheDirectory, file);
            if (imageRequest.RefreshImage || !zFile.Exists(path))
                HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            webImage.File = file;

            if (zFile.Exists(path))
            {
                Image image = LoadImageFromFile(path);
                if (image != null)
                {
                    webImage.Width = image.Width;
                    webImage.Height = image.Height;
                    if (imageRequest.LoadImageToData)
                        webImage.Image = image;
                }
            }
            return true;
        }
开发者ID:labeuze,项目名称:source,代码行数:26,代码来源:WebImageCacheManager_v2.cs


示例2: LoadImage

 //Predicate<ImageMongoCache> filter = null
 public bool LoadImage(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null)
 {
     //Trace.WriteLine($"WebImageMongo.LoadImage() : \"{webImage.Url}\"    _imageCacheManager {_imageCacheManager}");
     if (webImage.Url != null && webImage.Image == null)
     {
         try
         {
             Image image = null;
             if (_imageCacheManager != null)
             {
                 ImageMongoCache imageCache = (ImageMongoCache)_imageCacheManager.GetImageCache(webImage.Url, requestParameters);
                 //if (_imageFilter != null && !_imageFilter(imageCache))
                 //    return false;
                 image = imageCache.Image;
             }
             else if (imageRequest.LoadImageFromWeb)
                 image = HttpManager.CurrentHttpManager.LoadImage(new HttpRequest { Url = webImage.Url }, requestParameters);
             if (imageRequest.LoadImageToData)
                 webImage.Image = image;
         }
         catch (Exception ex)
         {
             Trace.WriteLine("error loading image \"{0}\"", webImage.Url);
             Trace.WriteLine(ex.Message);
             //return false;
         }
     }
     return true;
 }
开发者ID:labeuze,项目名称:source,代码行数:30,代码来源:WebImageMongoManager.cs


示例3: SimpleGetBytesClonesArray

        public void SimpleGetBytesClonesArray()
        {
            WebImage image = new WebImage(_PngImageBytes);

            byte[] returnedContent = image.GetBytes();

            Assert.False(ReferenceEquals(_PngImageBytes, returnedContent), "GetBytes should clone array.");
            Assert.Equal(_PngImageBytes, returnedContent);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:WebImageTest.cs


示例4: FilePathReturnsCorrectPath

        public void FilePathReturnsCorrectPath()
        {
            // Arrange
            string imageName = @"x:\My-test-image.png";

            // Act
            WebImage image = new WebImage(GetContext(), s => _PngImageBytes, imageName);

            // Assert
            Assert.Equal(imageName, image.FileName);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:11,代码来源:WebImageTest.cs


示例5: FilePathCanBeSet

        public void FilePathCanBeSet()
        {
            // Arrange
            string originalPath = @"x:\somePath.png";
            string newPath = @"x:\someOtherPath.jpg";

            // Act
            WebImage image = new WebImage(GetContext(), s => _PngImageBytes, originalPath);
            image.FileName = newPath;

            // Assert
            Assert.Equal(newPath, image.FileName);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:13,代码来源:WebImageTest.cs


示例6: LoadImageToData

 protected void LoadImageToData(WebImage webImage)
 {
     if (webImage.File == null || webImage.Image != null)
         return;
     // _urlCache.CacheDirectory
     string path = zPath.Combine(GetCacheDirectory(), webImage.File);
     if (path != null && zFile.Exists(path))
     {
         webImage.Image = LoadImageFromFile(path);
     }
     else
     {
         Trace.WriteLine("error unable to load image url \"{0}\" from file \"{1}\"", webImage.Url, path);
     }
 }
开发者ID:labeuze,项目名称:source,代码行数:15,代码来源:WebImageCacheManager_v3.cs


示例7: LoadImage

 public static bool LoadImage(WebImage image, HttpRequestParameters_v1 requestParameters = null, Predicate<ImageMongoCache_v1> filter = null)
 {
     if (image.Url != null && image.Image == null)
     {
         if (__imageCacheManager != null)
         {
             ImageMongoCache_v1 imageCache = (ImageMongoCache_v1)__imageCacheManager.GetImageCache(image.Url, requestParameters);
             if (filter != null && !filter(imageCache))
                 return false;
             image.Image = imageCache.Image;
         }
         else
             image.Image = pb.old.Http_v2.LoadImageFromWeb(image.Url, requestParameters);
     }
     return true;
 }
开发者ID:labeuze,项目名称:source,代码行数:16,代码来源:FreeTelechargement.cs


示例8: WebImageViewModel

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="source">関連付けるWebImageオブジェクト</param>
        /// <param name="visionApiSubscriptionKey">Microsoft Vision API のSubscription Key</param>
        /// <param name="logger">ログメッセージ通知オブジェクト</param>
        public WebImageViewModel(WebImage source, string visionApiSubscriptionKey, ILogger logger)
        {
            this.source = source;
            this.logger = logger;
            this.visionApiSubscriptionKey = visionApiSubscriptionKey;

            //Model(WebImage)のプロパティをReactivePropertyに変換
            Thumbnail = source.ObserveProperty(x => x.Thumbnail).ToReadOnlyReactiveProperty();
            DisplayImage = source.ObserveProperty(x => x.DisplayImage).ToReadOnlyReactiveProperty();
            Overlay = source.ObserveProperty(x => x.Overlay).ToReadOnlyReactiveProperty();
            SourceUrl = source.ObserveProperty(x => x.SourceUrl).ToReadOnlyReactiveProperty();
            SourceTitle = source.ObserveProperty(x => x.SourceTitle).ToReadOnlyReactiveProperty();
            ImageProperty = source.ObserveProperty(x => x.ImageProperty).ToReadOnlyReactiveProperty();

            //実行中フラグ
            IsProcessing = progress.IsProcessingObservable.StartWith(false)
                .ToReadOnlyReactiveProperty();

            //プログレスバーの表示切替 - 実行中のみ表示する
            ProgressVisibility = IsProcessing
                .Select(x => x ? Visibility.Visible : Visibility.Collapsed)
                .ToReadOnlyReactiveProperty();

            //画像のサイズ変更時に実行するコマンド
            SizeChangedCommand = new ReactiveCommand<Size>();
            SizeChangedCommand
                .DistinctUntilChanged()
                .Throttle(TimeSpan.FromMilliseconds(200))
                .Subscribe(size =>
                {
                    //現在のサイズで 顔領域の矩形を再描画
                    source.DrawFaceRect(size);
                    //最新のサイズを保存しておく ⇒画像再選択時に使う
                    imageSize = size;
                })
                .AddTo(disposables);

            //リンク元ページURLのハイパーリンククリック時
            NavigateCommand = new ReactiveCommand();
            NavigateCommand.Subscribe(_ =>
            {
                Process.Start(source.SourceUrl);
            }).AddTo(disposables);

        }
开发者ID:pierre3,项目名称:ReactiveBingViewer,代码行数:51,代码来源:WebImageViewModel.cs


示例9: LoadImageFromWeb

        // HttpRequestParameters requestParameters = null
        protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage))
                return false;
            HttpRequest httpRequest = new HttpRequest { Url = webImage.Url, ReloadFromWeb = imageRequest.RefreshImage };

            //string file = _urlCache.GetUrlSubPath(httpRequest);
            //if (subDirectory != null)
            //    file = zPath.Combine(subDirectory, file);
            //string path = zPath.Combine(_urlCache.CacheDirectory, file);

            //if (imageRequest.RefreshImage || !zFile.Exists(path))
            //    HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            //webImage.File = file;

            //UrlCachePathResult urlCachePath = LoadHttpToCache(httpRequest, subDirectory);
            //webImage.File = urlCachePath.SubPath;
            //string path = urlCachePath.Path;

            //if (zFile.Exists(path))
            //{
            //    Image image = LoadImageFromFile(path);
            //    if (image != null)
            //    {
            //        webImage.Width = image.Width;
            //        webImage.Height = image.Height;
            //        if (imageRequest.LoadImageToData)
            //            webImage.Image = image;
            //    }
            //}

            HttpResult<Image> httpResult = LoadImage(httpRequest, subDirectory);
            if (httpResult.Success)
            {
                Image image = httpResult.Data;
                webImage.File = httpResult.Http.HttpRequest.UrlCachePath?.SubPath;
                webImage.Width = image.Width;
                webImage.Height = image.Height;
                if (imageRequest.LoadImageToData)
                    webImage.Image = image;
                return true;
            }
            else
                return false;
        }
开发者ID:labeuze,项目名称:source,代码行数:46,代码来源:WebImageCacheManager_v3.cs


示例10: LoadImageToData

 protected void LoadImageToData(WebImage webImage)
 {
     if (webImage.File == null || webImage.Image != null)
         return;
     string path = zPath.Combine(_urlCache.CacheDirectory, webImage.File);
     if (path != null && zFile.Exists(path))
     {
         //try
         //{
         //    webImage.Image = zimg.LoadFromFile(path);
         //}
         //catch (Exception exception)
         //{
         //    Trace.WriteLine("error unable to load image url \"{0}\" from file \"{1}\"", webImage.Url, path);
         //    Trace.Write("error : ");
         //    Trace.WriteLine(exception.Message);
         //}
         webImage.Image = LoadImageFromFile(path);
     }
     else
     {
         Trace.WriteLine("error unable to load image url \"{0}\" from file \"{1}\"", webImage.Url, path);
     }
 }
开发者ID:labeuze,项目名称:source,代码行数:24,代码来源:WebImageCacheManager_v2.cs


示例11: AddImageWatermarkDoesNotChangeImageIfWatermarkIsTooBig

        public void AddImageWatermarkDoesNotChangeImageIfWatermarkIsTooBig()
        {
            WebImage watermark = new WebImage(_JpgImageBytes);
            WebImage image = new WebImage(_BmpImageBytes);
            byte[] originalBytes = image.GetBytes("jpg");

            // This will use original watermark image dimensions which is bigger than the target image.
            image.AddImageWatermark(watermark);
            byte[] watermarkedBytes = image.GetBytes("jpg");

            Assert.Equal(originalBytes, watermarkedBytes);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:12,代码来源:WebImageTest.cs


示例12: AddImageWatermarkThrowsOnNegativePadding

        public void AddImageWatermarkThrowsOnNegativePadding()
        {
            WebImage watermark = new WebImage(_BmpImageBytes);
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.ThrowsArgumentGreaterThanOrEqualTo(
                () => image.AddImageWatermark(watermark, padding: -10),
                "padding",
                "0");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:10,代码来源:WebImageTest.cs


示例13: AddImageWatermarkDoesNotChangeWatermarkImage

        public void AddImageWatermarkDoesNotChangeWatermarkImage()
        {
            WebImage watermark = new WebImage(_BmpImageBytes);
            WebImage image = new WebImage(_JpgImageBytes);
            image.AddImageWatermark(watermark, width: 54, height: 22, horizontalAlign: "LEFT", verticalAlign: "top", opacity: 50, padding: 10);

            Assert.Equal(108, watermark.Width);
            Assert.Equal(44, watermark.Height);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:WebImageTest.cs


示例14: SaveUsesOriginalFormatForStreamsWhenNoFormatIsSpecified

        public void SaveUsesOriginalFormatForStreamsWhenNoFormatIsSpecified()
        {
            // Arrange
            // Use rooted path so we by pass using HttpContext
            var specifiedOutputFile = @"x:\some-dir\foo.jpg";
            string actualOutputFile = null;
            Action<string, byte[]> saveAction = (fileName, content) => { actualOutputFile = fileName; };

            // Act
            WebImage image = new WebImage(_PngImageBytes);
            image.Save(GetContext(), saveAction, filePath: specifiedOutputFile, imageFormat: null, forceWellKnownExtension: true);

            // Assert
            Assert.Equal(Path.GetExtension(actualOutputFile), ".png");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:15,代码来源:WebImageTest.cs


示例15: SaveThrowsWhenPathIsNull

        public void SaveThrowsWhenPathIsNull()
        {
            Action<string, byte[]> saveAction = (path, content) => { };

            // this constructor will not set path
            byte[] originalContent = _BmpImageBytes;
            WebImage image = new WebImage(originalContent);

            Assert.ThrowsArgumentNullOrEmptyString(
                () => image.Save(GetContext(), saveAction, filePath: null, imageFormat: null, forceWellKnownExtension: true),
                "filePath");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:12,代码来源:WebImageTest.cs


示例16: CanAddImageWatermarkWithFileName

        public void CanAddImageWatermarkWithFileName()
        {
            // Arrange
            var context = GetContext();
            WebImage image = new WebImage(_BmpImageBytes);
            WebImage watermark = new WebImage(_JpgImageBytes);

            // Act
            var watermarkedWithImageArgument = image.AddImageWatermark(watermark).GetBytes();
            var watermarkedWithFilePathArgument = image.AddImageWatermark(context, (name) => _JpgImageBytes, @"x:\jpegimage.jpg", width: 0, height: 0, horizontalAlign: "Right", verticalAlign: "Bottom", opacity: 100, padding: 5).GetBytes();

            Assert.Equal(watermarkedWithImageArgument, watermarkedWithFilePathArgument);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:13,代码来源:WebImageTest.cs


示例17: AddImageWatermarkWithFileNameThrowsExceptionWhenWatermarkFileDoesNotExist

 public void AddImageWatermarkWithFileNameThrowsExceptionWhenWatermarkFileDoesNotExist()
 {
     var context = GetContext();
     WebImage image = new WebImage(_BmpImageBytes);
     Assert.Throws<FileNotFoundException>(
         () => image.AddImageWatermark(context, s => { throw new FileNotFoundException(); }, @"x:\there-is-no-file.jpg", width: 0, height: 0, horizontalAlign: "Right", verticalAlign: "Bottom", opacity: 100, padding: 5));
 }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:7,代码来源:WebImageTest.cs


示例18: AddImageWatermarkWithFileNameThrowsExceptionWhenWatermarkDirectoryDoesNotExist

        public void AddImageWatermarkWithFileNameThrowsExceptionWhenWatermarkDirectoryDoesNotExist()
        {
            var context = GetContext();
            WebImage image = new WebImage(_BmpImageBytes);

            Assert.Throws<DirectoryNotFoundException>(
                () => image.AddImageWatermark(context, s => { throw new DirectoryNotFoundException(); }, @"x:\path\does\not\exist", width: 0, height: 0, horizontalAlign: "Right", verticalAlign: "Bottom", opacity: 100, padding: 5));
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:8,代码来源:WebImageTest.cs


示例19: WebImagePreservesOriginalFormatFromFile

        public void WebImagePreservesOriginalFormatFromFile()
        {
            WebImage image = new WebImage(_PngImageBytes);

            byte[] returnedContent = image.GetBytes();

            // If format was changed; content would be different
            Assert.Equal(_PngImageBytes, returnedContent);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:WebImageTest.cs


示例20: AddImageWatermarkThrowsOnNullImage

        public void AddImageWatermarkThrowsOnNullImage()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.ThrowsArgumentNull(
                () => image.AddImageWatermark(watermarkImage: null),
                "watermarkImage");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:8,代码来源:WebImageTest.cs



注:本文中的WebImage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WebMediaType类代码示例发布时间:2022-05-24
下一篇:
C# WebHeaderCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap