当前位置: 首页>>代码示例>>C#>>正文


C# ImageFileType.ToFileExtension方法代码示例

本文整理汇总了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.");
            }
        }
开发者ID:cg123,项目名称:xenko,代码行数:13,代码来源:TexturePackerTests.cs

示例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);
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:71,代码来源:TestImage.cs


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