本文整理汇总了C#中WebImage类的典型用法代码示例。如果您正苦于以下问题:C# WebImage类的具体用法?C# WebImage怎么用?C# WebImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebImage类属于命名空间,在下文中一共展示了WebImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例12: AddImageWatermarkThrowsOnNegativePadding
public void AddImageWatermarkThrowsOnNegativePadding()
{
WebImage watermark = new WebImage(_BmpImageBytes);
WebImage image = new WebImage(_JpgImageBytes);
Assert.ThrowsArgumentGreaterThanOrEqualTo(
() => image.AddImageWatermark(watermark, padding: -10),
"padding",
"0");
}
示例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);
}
示例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");
}
示例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");
}