本文整理汇总了C#中ImageFileType类的典型用法代码示例。如果您正苦于以下问题:C# ImageFileType类的具体用法?C# ImageFileType怎么用?C# ImageFileType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageFileType类属于命名空间,在下文中一共展示了ImageFileType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyImage
private static void CopyImage(string file, ImageFileType type)
{
string newFileFullPath = Path.Combine(destFolder, Path.GetFileName(file));
if (type == ImageFileType.Jpeg)
newFileFullPath += ".jpg";
else if (type == ImageFileType.Png)
newFileFullPath += ".png";
if (File.Exists(newFileFullPath))
return;
if (ImageHelper.IsMobileSizeImage(file))
return;
try
{
if (!Directory.Exists(destFolder))
Directory.CreateDirectory(destFolder);
File.Copy(file, newFileFullPath);
}
catch (Exception)
{
}
}
示例2: RasterImage
public RasterImage(BitmapSource source, ImageFileType fileType)
{
this.source = source;
this.fileType = fileType;
this.frames = new List<IFrame>(1)
{
new RasterFrame(source)
};
}
示例3: ImageSearchData
internal ImageSearchData(SearchData result, Uri refUrl, Uri refClkUrl, long fileSize, ImageFileType fileFormat, int height, int width, Uri tmbUrl, int tmbHeight, int tmbWidth)
: base(result.Title, result.Description, result.Url, result.ClickUrl)
{
mRefererUrl = refUrl;
mRefererClickUrl = refClkUrl;
mFileSize = fileSize;
mFileFormat = fileFormat;
mHeight = height;
mWidth = width;
mThumbnail = new Thumbnail(tmbUrl, tmbHeight, tmbWidth);
}
示例4: Capture
public static void Capture( GraphicsDevice device, string filePath = null, ImageFileType format = ImageFileType.Png )
{
if( filePath == null )
{
if( !Directory.Exists( defaultFolder ) )
{
Directory.CreateDirectory( defaultFolder );
}
filePath = Path.Combine( defaultFolder, defaultName + "_" + ( FileCount( defaultFolder ) + 1 ).ToString() + "." + format.ToString().ToLower() );
}
device.BackBuffer.Save( filePath, format );
}
示例5: GetFileType
string GetFileType (ImageFileType type)
{
switch (type) {
case ImageFileType.Bmp:
return "bmp";
case ImageFileType.Jpeg:
return "jpeg";
case ImageFileType.Png:
return "png";
default:
throw new NotSupportedException ();
}
}
示例6: RtfImage
internal RtfImage(string fileName, ImageFileType type)
{
_imgFname = fileName;
_imgType = type;
_alignment = Align.None;
_margins = new Margins();
_keepAspectRatio = true;
_blockHead = @"{\pard";
_blockTail = @"\par}";
_startNewPage = false;
Image image = Image.FromFile(fileName);
_width = (image.Width / image.HorizontalResolution) * 72;
_height = (image.Height / image.VerticalResolution) * 72;
}
示例7: OutputSet
public OutputSet(SourceImage owner, string name)
{
this.owner = owner;
this.name = name;
this.description = string.Empty;
this.expanded = true;
this.transformType = ImageTransformType.None;
this.outputType = ImageHelpers.IsBitmapType(owner.Image.FileType)
? owner.Image.FileType
: ImageFileType.DefaultRasterize;
this.images = new ObservableCollection<OutputImage>();
this.UpdateSize();
owner.PropertyChanged += this.OnOwnerPropertyChanged;
}
示例8: Image
/// <summary>
/// Create a new image.
/// </summary>
/// <param name="Url">URL from where the image data can be fetched through a web browser (about 512 pixels).</param>
/// <param name="Thumbnail">URL from where a thumbnail of the image can be fetched through a webbrowser (about 128 pixels).</param>
/// <param name="Category">Describes what the image is used for.</param>
/// <param name="Type">Image type like: gif, jpeg, png, svg.</param>
/// <param name="Width">Width of the full scale image.</param>
/// <param name="Height">Height of the full scale image.</param>
public Image(Uri Url,
Uri Thumbnail,
ImageCategoryType Category,
ImageFileType Type,
UInt32 Width,
UInt32 Height)
{
#region Initial checks
if (Url == null)
throw new ArgumentNullException("Url", "The given parameter must not be null!");
#endregion
this._Url = Url;
this._Thumbnail = Thumbnail;
this._Category = Category;
this._Type = Type;
this._Width = Width;
this._Height = Height;
}
示例9: SearchGalleryAdvancedRequest
/// <exception cref="ArgumentNullException">
/// Thrown when a null reference is passed to a method that does not accept it as a
/// valid argument.
/// </exception>
internal string SearchGalleryAdvancedRequest(string url,
string qAll = null, string qAny = null,
string qExactly = null, string qNot = null,
ImageFileType? fileType = null, ImageSize? imageSize = null)
{
if (string.IsNullOrWhiteSpace(url))
throw new ArgumentNullException(nameof(url));
if (string.IsNullOrWhiteSpace(qAll) &&
string.IsNullOrWhiteSpace(qAny) &&
string.IsNullOrWhiteSpace(qExactly) &&
string.IsNullOrWhiteSpace(qNot))
throw new ArgumentNullException(null,
"At least one search parameter must be provided (All | Any | Exactly | Not).");
var query = new StringBuilder();
if (!string.IsNullOrWhiteSpace(qAll))
query.Append($"&q_all={WebUtility.UrlEncode(qAll)}");
if (!string.IsNullOrWhiteSpace(qAny))
query.Append($"&q_any={WebUtility.UrlEncode(qAny)}");
if (!string.IsNullOrWhiteSpace(qExactly))
query.Append($"&q_exactly={WebUtility.UrlEncode(qExactly)}");
if (!string.IsNullOrWhiteSpace(qNot))
query.Append($"&q_not={WebUtility.UrlEncode(qNot)}");
if (fileType != null)
query.Append($"&q_type={WebUtility.UrlEncode(fileType.ToString().ToLower())}");
if (imageSize != null)
query.Append($"&q_size_px={WebUtility.UrlEncode(imageSize.ToString().ToLower())}");
return $"{url}?{query}".Replace("?&", "?");
}
示例10: GetScaledPath
public string GetScaledPath(double scale, string fileNameOverride = null, ImageFileType fileTypeOverride = ImageFileType.None)
{
string path;
int insertPos = -1;
if (string.IsNullOrEmpty(fileNameOverride))
{
path = this.pathScaleLength > 0
? this.path.Remove(this.pathScaleStart, this.pathScaleLength - 1)
: this.path;
insertPos = this.pathScaleStart;
}
else
{
path = Path.Combine(this.FullDir, fileNameOverride);
insertPos = path.Length - Path.GetExtension(path).Length;
}
if (insertPos != -1 && scale > 0)
{
path = path.Insert(insertPos, $".scale-{(int)(scale * 100.0)}");
}
if (fileTypeOverride != ImageFileType.None && fileTypeOverride != this.Image.FileType)
{
string oldExtension = Path.GetExtension(path);
string newExtension = oldExtension;
switch (fileTypeOverride)
{
case ImageFileType.Bmp:
newExtension = ".bmp";
break;
case ImageFileType.Jpeg:
newExtension = ".jpg";
break;
case ImageFileType.Png:
newExtension = ".png";
break;
default:
Debug.Fail("Can't save with file extension for: " + fileTypeOverride);
break;
}
if (oldExtension != newExtension)
{
path = path.Remove(path.Length - oldExtension.Length, oldExtension.Length) + newExtension;
}
}
return path;
}
示例11: Save
public void Save(string file, ImageFileType fileType)
{
using (var f = File.OpenWrite (file))
Save (f, fileType);
}
示例12: TestLoadAndSave
public void TestLoadAndSave()
{
var dxsdkDir = Environment.GetEnvironmentVariable("DXSDK_DIR");
if (string.IsNullOrEmpty(dxsdkDir))
throw new NotSupportedException("Install DirectX SDK June 2010 to run this test (DXSDK_DIR env variable is missing).");
GC.Collect();
GC.WaitForFullGCComplete();
testMemoryBefore = GC.GetTotalMemory(true);
var files = new List<string>();
files.AddRange(Directory.EnumerateFiles(Path.Combine(dxsdkDir, @"Samples\Media"), "*.dds", SearchOption.AllDirectories));
files.AddRange(Directory.EnumerateFiles(Path.Combine(dxsdkDir, @"Samples\Media"), "*.jpg", SearchOption.AllDirectories));
files.AddRange(Directory.EnumerateFiles(Path.Combine(dxsdkDir, @"Samples\Media"), "*.bmp", SearchOption.AllDirectories));
const int Count = 1; // Change this to perform memory benchmarks
var types = new ImageFileType[] {
ImageFileType.Dds,
};
for (int i = 0; i < Count; i++)
{
for (int j = 0; j < types.Length; j++)
{
Console.Write("[{0}] ", i);
ProcessFiles(files, types[j]);
}
}
}
示例13: ProcessFiles
private void ProcessFiles(IEnumerable<string> files, ImageFileType intermediateFormat)
{
Console.WriteLine("Testing {0}", intermediateFormat);
Console.Out.Flush();
int imageCount = 0;
var clock = Stopwatch.StartNew();
foreach (var file in files)
{
// Load an image from a file and dispose it.
Image image;
using (var inStream = File.OpenRead(file))
image = Image.Load(inStream);
image.Dispose();
// Load an image from a buffer
var buffer = File.ReadAllBytes(file);
using (image = Image.Load(buffer))
{
// Write this image to a memory stream using DDS format.
var tempStream = new MemoryStream();
image.Save(tempStream, intermediateFormat);
tempStream.Position = 0;
// Save to a file on disk
var name = Enum.GetName(typeof(ImageFileType), intermediateFormat).ToLower();
using (var outStream = File.OpenWrite(Path.ChangeExtension(Path.GetFileName(file), name)))
image.Save(outStream, intermediateFormat);
if (intermediateFormat == ImageFileType.Dds)
{
// Reload the image from the memory stream.
var image2 = Image.Load(tempStream);
CompareImage(image, image2, file);
image2.Dispose();
}
}
imageCount++;
}
var time = clock.ElapsedMilliseconds;
clock.Stop();
GC.Collect();
GC.WaitForPendingFinalizers();
var testMemoryAfter = GC.GetTotalMemory(true);
Console.WriteLine("Loaded {0} and convert to (Dds, Jpg, Png, Gif, Bmp, Tiff) image from DirectXSDK test Memory: {1} bytes, in {2}ms", imageCount, testMemoryAfter - testMemoryBefore, time);
}
示例14: GetContainerFormatFromFileType
private static Guid GetContainerFormatFromFileType(ImageFileType fileType)
{
switch (fileType)
{
case ImageFileType.Bmp:
return ContainerFormatGuids.Bmp;
case ImageFileType.Jpg:
return ContainerFormatGuids.Jpeg;
case ImageFileType.Gif:
return ContainerFormatGuids.Gif;
case ImageFileType.Png:
return ContainerFormatGuids.Png;
case ImageFileType.Tiff:
return ContainerFormatGuids.Tiff;
case ImageFileType.Wmp:
return ContainerFormatGuids.Wmp;
default:
throw new NotSupportedException("Format not supported");
}
}
示例15: SaveToWICMemory
private static void SaveToWICMemory(PixelBuffer[] pixelBuffer, int count, WICFlags flags, ImageFileType fileType, Stream stream)
{
if (count > 1)
EncodeMultiframe(pixelBuffer, count, flags, GetContainerFormatFromFileType(fileType), stream);
else
EncodeSingleFrame(pixelBuffer[0], flags, GetContainerFormatFromFileType(fileType), stream);
}