本文整理汇总了C#中ImageFormat.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ImageFormat.ToString方法的具体用法?C# ImageFormat.ToString怎么用?C# ImageFormat.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUri
/// <summary>
/// Gets the full path to the image asset, suitable for current screen resolution
/// </summary>
/// <param name="path">Path to image asset, relative to app root</param>
/// <returns></returns>
public static Uri GetUri(string path, ImageFormat imageFormat = ImageFormat.JPG) {
switch (ResolutionHelper.CurrentResolution) {
case Resolutions.HD:
return new Uri("{0}.Screen-720p.{1}".FormatWith(path, imageFormat.ToString().ToLowerInvariant()), UriKind.Relative);
case Resolutions.WXGA:
return new Uri("{0}.Screen-WXGA.{1}".FormatWith(path, imageFormat.ToString().ToLowerInvariant()), UriKind.Relative);
case Resolutions.WVGA:
return new Uri("{0}.Screen-WVGA.{1}".FormatWith(path, imageFormat.ToString().ToLowerInvariant()), UriKind.Relative);
default:
throw new InvalidOperationException("Unknown resolution type");
}
}
示例2: CreateImageBuilder
public override object CreateImageBuilder (int width, int height, ImageFormat format)
{
var flags = CGBitmapFlags.ByteOrderDefault;
int bytesPerRow;
switch (format) {
case ImageFormat.ARGB32:
bytesPerRow = width * 4;
flags |= CGBitmapFlags.PremultipliedFirst;
break;
case ImageFormat.RGB24:
bytesPerRow = width * 3;
flags |= CGBitmapFlags.None;
break;
default:
throw new NotImplementedException ("ImageFormat: " + format.ToString ());
}
var bmp = new CGBitmapContext (IntPtr.Zero, width, height, 8, bytesPerRow, Util.DeviceRGBColorSpace, flags);
bmp.TranslateCTM (0, height);
bmp.ScaleCTM (1, -1);
return new CGContextBackend {
Context = bmp,
Size = new CGSize (width, height),
InverseViewTransform = bmp.GetCTM ().Invert ()
};
}
示例3: TakeScreenShot
public static void TakeScreenShot(IWebDriver webDriver, string screenShotFileNameWithoutExtension, ImageFormat imageFormat, string screenShotDirectoryPath) {
Screenshot screenShot = null;
var browserName = string.Empty;
if (webDriver.GetType() == typeof(InternetExplorerDriver)) {
screenShot = ((InternetExplorerDriver)webDriver).GetScreenshot();
browserName = "IE";
}
if (webDriver.GetType() == typeof(FirefoxDriver)) {
screenShot = ((FirefoxDriver)webDriver).GetScreenshot();
browserName = "Firefox";
}
if (webDriver.GetType() == typeof(ChromeDriver)) {
screenShot = ((ChromeDriver)webDriver).GetScreenshot();
browserName = "Chrome";
}
var screenShotFileName = screenShotFileNameWithoutExtension + "." + imageFormat.ToString().ToLower();
if (screenShot != null) {
if (!string.IsNullOrEmpty(screenShotDirectoryPath)) {
Directory.CreateDirectory(screenShotDirectoryPath).CreateSubdirectory(browserName);
var browserScreenShotDirectoryPath = Path.Combine(screenShotDirectoryPath, browserName);
Directory.CreateDirectory(browserScreenShotDirectoryPath);
var screenShotFileFullPath = Path.Combine(browserScreenShotDirectoryPath, screenShotFileName);
screenShot.SaveAsFile(screenShotFileFullPath, imageFormat);
}
}
}
示例4: FromStream
public static Image FromStream(Stream stream, ImageFormat format)
{
switch (format)
{
case ImageFormat.Tga:
return Tga.FromStream(stream);
}
throw new NotImplementedException("ImageFormat." + format.ToString() + " not implemented.");
}
示例5: GetImageAsync
public Task<IControl> GetImageAsync(ImageSource imageSource, ImageFormat format, CancellationToken cancellationToken)
{
var fileSource = (FileImageSource)imageSource;
string asset = fileSource.File;
if (format == ImageFormat.Unknown)
format = ImageFactory.DetectFormat(asset);
string cacheKey = format.ToString() + "|" + asset;
return _cachedImages.GetOrAdd(cacheKey, k => GetImage(fileSource, format));
}
示例6: GetImageAsync
public Task<IControl> GetImageAsync(ImageSource imageSource, ImageFormat format, CancellationToken cancellationToken)
{
var uriSource = (UriImageSource)imageSource;
if (uriSource.Uri.Scheme == "pack")
uriSource.CachingEnabled = false;
string asset = uriSource.Uri.ToString();
if (format == ImageFormat.Unknown)
format = ImageFactory.DetectFormat(asset);
string cacheKey = format.ToString() + "|" + asset;
return _cachedImages.GetOrAdd(cacheKey, k => GetImage(uriSource, format));
}
示例7: ConvertPDF2Image
/// <summary>
/// 将PDF文档转换为图片的方法
/// </summary>
/// <param name="pdfInputPath">PDF文件路径</param>
/// <param name="imageOutputPath">图片输出路径</param>
/// <param name="imageName">生成图片的名字</param>
/// <param name="startPageNum">从PDF文档的第几页开始转换</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换</param>
/// <param name="imageFormat">设置所需图片格式</param>
/// <param name="definition">设置图片的清晰度,数字越大越清晰</param>
public static void ConvertPDF2Image(string pdfInputPath, string imageOutputPath,
string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, Definition definition)
{
PDFFile pdfFile = PDFFile.Open(pdfInputPath);
if (!Directory.Exists(imageOutputPath))
{
Directory.CreateDirectory(imageOutputPath);
}
// validate pageNum
if (startPageNum <= 0)
{
startPageNum = 1;
}
if (endPageNum > pdfFile.PageCount)
{
endPageNum = pdfFile.PageCount;
}
if (startPageNum > endPageNum)
{
int tempPageNum = startPageNum;
startPageNum = endPageNum;
endPageNum = startPageNum;
}
// start to convert each page
try
{
for (int i = startPageNum; i <= endPageNum; i++)
{
Bitmap pageImage = pdfFile.GetPageImage(i - 1, 56 * (int)definition);
pageImage.Save(imageOutputPath + imageName + i.ToString() + "." + imageFormat.ToString(), imageFormat);
pageImage.Dispose();
}
}
catch (System.Exception ex)
{
}
pdfFile.Dispose();
}
示例8: CreateImageBuilder
public override object CreateImageBuilder(int width, int height, ImageFormat format)
{
var flags = CGBitmapFlags.ByteOrderDefault;
int bytesPerRow;
switch (format) {
case ImageFormat.ARGB32:
bytesPerRow = width * 4;
flags |= CGBitmapFlags.PremultipliedFirst;
break;
case ImageFormat.RGB24:
bytesPerRow = width * 3;
flags |= CGBitmapFlags.None;
break;
default:
throw new NotImplementedException ("ImageFormat: " + format.ToString ());
}
return new CGContextBackend {
Context = new CGBitmapContext (IntPtr.Zero, width, height, 8, bytesPerRow, Util.DeviceRGBColorSpace, flags),
Size = new SizeF (width, height)
};
}
示例9: GetCacheFilePath
/// <summary>
/// Gets the cache file path based on a set of parameters
/// </summary>
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, string backgroundColor)
{
var filename = originalPath;
filename += "width=" + outputSize.Width;
filename += "height=" + outputSize.Height;
filename += "quality=" + quality;
filename += "datemodified=" + dateModified.Ticks;
filename += "f=" + format;
if (addPlayedIndicator)
{
filename += "pl=true";
}
if (percentPlayed > 0)
{
filename += "p=" + percentPlayed;
}
if (unwatchedCount.HasValue)
{
filename += "p=" + unwatchedCount.Value;
}
if (!string.IsNullOrEmpty(backgroundColor))
{
filename += "b=" + backgroundColor;
}
filename += "v=" + Version;
return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower());
}
示例10: ConvertToBitmap
public override object ConvertToBitmap(object handle, double width, double height, double scaleFactor, ImageFormat format)
{
int pixelWidth = (int)(width * scaleFactor);
int pixelHeight = (int)(height * scaleFactor);
if (handle is CustomImage) {
var flags = CGBitmapFlags.ByteOrderDefault;
int bytesPerRow;
switch (format) {
case ImageFormat.ARGB32:
bytesPerRow = pixelWidth * 4;
flags |= CGBitmapFlags.PremultipliedFirst;
break;
case ImageFormat.RGB24:
bytesPerRow = pixelWidth * 3;
flags |= CGBitmapFlags.None;
break;
default:
throw new NotImplementedException ("ImageFormat: " + format.ToString ());
}
var bmp = new CGBitmapContext (IntPtr.Zero, pixelWidth, pixelHeight, 8, bytesPerRow, Util.DeviceRGBColorSpace, flags);
bmp.TranslateCTM (0, pixelHeight);
bmp.ScaleCTM ((float)scaleFactor, (float)-scaleFactor);
var ctx = new CGContextBackend {
Context = bmp,
Size = new SizeF ((float)width, (float)height),
InverseViewTransform = bmp.GetCTM ().Invert (),
ScaleFactor = scaleFactor
};
var ci = (CustomImage)handle;
ci.DrawInContext (ctx);
var img = new NSImage (((CGBitmapContext)bmp).ToImage (), new SizeF (pixelWidth, pixelHeight));
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep)NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
im.Size = new SizeF ((float)width, (float)height);
bmp.Dispose ();
return im;
}
else {
NSImage img = (NSImage)handle;
NSBitmapImageRep bitmap = img.Representations ().OfType<NSBitmapImageRep> ().FirstOrDefault ();
if (bitmap == null) {
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep)NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
im.Size = new SizeF ((float)width, (float)height);
return im;
}
return handle;
}
}
示例11: GetSavePaths
public IEnumerable<string> GetSavePaths(IHasImages item, ImageType type, ImageFormat format, int index)
{
var season = item as Season;
if (!SupportsItem(item, type, season))
{
return new string[] { };
}
var extension = "." + format.ToString().ToLower();
// Backdrop paths
if (type == ImageType.Backdrop)
{
if (index == 0)
{
if (item.IsInMixedFolder)
{
return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) };
}
if (season != null && season.IndexNumber.HasValue)
{
var seriesFolder = season.SeriesPath;
var seasonMarker = season.IndexNumber.Value == 0
? "-specials"
: season.IndexNumber.Value.ToString("00", _usCulture);
var imageFilename = "season" + seasonMarker + "-fanart" + extension;
return new[] { Path.Combine(seriesFolder, imageFilename) };
}
return new[]
{
Path.Combine(item.ContainingFolderPath, "fanart" + extension)
};
}
if (item.IsInMixedFolder)
{
return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + index.ToString(_usCulture), extension) };
}
var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", index);
return new[]
{
Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension),
Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + index.ToString(_usCulture) + extension)
};
}
if (type == ImageType.Primary)
{
if (season != null && season.IndexNumber.HasValue)
{
var seriesFolder = season.SeriesPath;
var seasonMarker = season.IndexNumber.Value == 0
? "-specials"
: season.IndexNumber.Value.ToString("00", _usCulture);
var imageFilename = "season" + seasonMarker + "-poster" + extension;
return new[] { Path.Combine(seriesFolder, imageFilename) };
}
if (item is Episode)
{
var seasonFolder = Path.GetDirectoryName(item.Path);
var imageFilename = Path.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension;
return new[] { Path.Combine(seasonFolder, imageFilename) };
}
if (item.IsInMixedFolder || item is MusicVideo)
{
return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) };
}
if (item is MusicAlbum || item is MusicArtist)
{
return new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) };
}
return new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) };
}
if (type == ImageType.Banner)
{
if (season != null && season.IndexNumber.HasValue)
{
var seriesFolder = season.SeriesPath;
var seasonMarker = season.IndexNumber.Value == 0
? "-specials"
: season.IndexNumber.Value.ToString("00", _usCulture);
//.........这里部分代码省略.........
示例12: Save
public void Save(Stream stream, ImageFormat imageFormat, int quality)
{
if (this._disposed)
{
throw new ObjectDisposedException("CompactImage");
}
if (this._handle != IntPtr.Zero)
{
Native.RIL_Save(this._handle, stream, imageFormat.ToString(), quality);
}
}
示例13: Load
public void Load(Stream stream, ImageFormat imageFormat, int frame, Color backgroundColor, LoadOptions loadOptions, System.Drawing.Size maxSize)
{
if (this._disposed)
{
throw new ObjectDisposedException("CompactImage");
}
if (this._handle != IntPtr.Zero)
{
Native.RIL_Close(this._handle);
}
Native.RLoadOut @out = Native.RIL_Load(null, stream, imageFormat.ToString(), frame, backgroundColor, loadOptions, maxSize, this._progressFunc);
this._handle = @out.Handle;
this._fullSize = (System.Drawing.Size) @out.FullSize;
this._size = (System.Drawing.Size) @out.Size;
this._depth = @out.Depth;
this._numberOfFrames = @out.NumberOfFrames;
this._loadedFrame = frame;
this.OnChanged();
}
示例14: Fit
/// <summary>
/// Fits the specified image to the supplied max width and height.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="maxWidth">Width of the max.</param>
/// <param name="maxHeight">Height of the max.</param>
/// <param name="fitMode">The fit mode.</param>
/// <param name="scaleMode">The scale mode.</param>
/// <param name="alignMode">The align mode.</param>
/// <param name="format">The format.</param>
/// <param name="quality">The quality.</param>
/// <param name="colors">The colors.</param>
/// <param name="bgColor">Color of the background.</param>
/// <returns></returns>
public static IFilteredImage Fit(this IFilteredImage image, int maxWidth, int maxHeight,
FitMode fitMode = FitMode.Pad, ScaleMode scaleMode = ScaleMode.Down,
AlignMode alignMode = AlignMode.MiddleCenter, ImageFormat format = ImageFormat.Auto,
int quality = 90, int colors = 256, string bgColor = "")
{
image.Filters.Add("w", maxWidth);
image.Filters.Add("h", maxHeight);
if(fitMode != FitMode.Pad)
image.Filters.Add("mode", fitMode.ToString().ToLower());
if(scaleMode != ScaleMode.Down)
image.Filters.Add("scale", scaleMode.ToString().ToLower());
if(alignMode != AlignMode.MiddleCenter)
image.Filters.Add("anchor", alignMode.ToString().ToLower());
if(format != ImageFormat.Auto)
image.Filters.Add("format", format.ToString().ToLower());
if(quality != 90)
image.Filters.Add("quality", Math.Min(100, Math.Max(0, quality)));
if (colors != 256)
image.Filters.Add("colors", Math.Min(256, Math.Max(2, quality)));
if (!string.IsNullOrEmpty(bgColor))
image.Filters.Add("bgcolor", bgColor);
return image;
}
示例15: Recorder
/// <summary>
/// Constructor
/// </summary>
/// <param name="imageFormat">Image Format to save images as</param>
public Recorder(ImageFormat imageFormat = null)
{
if (imageFormat == null)
return;
this.imageFormat = imageFormat;
this.imageExtension = "." + imageFormat.ToString().ToLower();
}