本文整理汇总了C#中ImageFileType.ToFileExtension方法的典型用法代码示例。如果您正苦于以下问题:C# ImageFileType.ToFileExtension方法的具体用法?C# ImageFileType.ToFileExtension怎么用?C# ImageFileType.ToFileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageFileType
的用法示例。
在下文中一共展示了ImageFileType.ToFileExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveAndCompareTexture
private void SaveAndCompareTexture(Image outputImage, string fileName, ImageFileType extension = ImageFileType.Png)
{
// save
Directory.CreateDirectory(ImageOutputPath);
outputImage.Save(new FileStream(ImageOutputPath + fileName + extension.ToFileExtension(), FileMode.Create), extension);
// Compare
using(var texTool = new TextureTool())
{
var referenceImage = LoadImage(texTool, new UFile(GoldImagePath + "/" + fileName + extension.ToFileExtension()));
Assert.IsTrue(CompareImages(outputImage, referenceImage), "The texture outputted differs from the gold image.");
}
}
示例2: ProcessFiles
private void ProcessFiles(Game game, ImageFileType sourceFormat, ImageFileType intermediateFormat)
{
Log.Info("Testing {0}", intermediateFormat);
Console.Out.Flush();
var imageCount = 0;
var clock = Stopwatch.StartNew();
// Load an image from a file and dispose it.
var fileName = sourceFormat.ToFileExtension().Substring(1) + "Image";
var filePath = "ImageTypes/" + fileName;
Image image;
using (var inStream = game.Asset.OpenAsStream(filePath, StreamFlags.None))
image = Image.Load(inStream);
image.Dispose();
// Load an image from a buffer
byte[] buffer;
using (var inStream = game.Asset.OpenAsStream(filePath, StreamFlags.None))
{
var bufferSize = inStream.Length;
buffer = new byte[bufferSize];
inStream.Read(buffer, 0, (int)bufferSize);
}
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 extension = intermediateFormat.ToFileExtension();
using (var outStream = VirtualFileSystem.ApplicationCache.OpenStream(fileName + extension, VirtualFileMode.Create, VirtualFileAccess.Write))
image.Save(outStream, intermediateFormat);
if (intermediateFormat == ImageFileType.Xenko || intermediateFormat == ImageFileType.Dds || (sourceFormat == intermediateFormat
&& intermediateFormat != ImageFileType.Gif)) // TODO: remove this when Giff compression/decompression is fixed
{
int allowSmallDifferences;
switch (intermediateFormat)
{
case ImageFileType.Tiff:// TODO: remove this when tiff encryption implementation is stable
case ImageFileType.Png: // TODO: remove this when png encryption implementation is stable
allowSmallDifferences = 1;
break;
case ImageFileType.Jpg: // TODO: remove this when jepg encryption implementation is stable
allowSmallDifferences = 30;
break;
default:
allowSmallDifferences = 0;
break;
}
// Reload the image from the memory stream.
var image2 = Image.Load(tempStream);
CompareImage(image, image2, false, allowSmallDifferences, fileName);
image2.Dispose();
}
}
imageCount++;
var time = clock.ElapsedMilliseconds;
clock.Stop();
GC.Collect();
GC.WaitForPendingFinalizers();
var testMemoryAfter = GC.GetTotalMemory(true);
Log.Info("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);
}