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


C# ContentProcessorContext.AddOutputFile方法代码示例

本文整理汇总了C#中ContentProcessorContext.AddOutputFile方法的典型用法代码示例。如果您正苦于以下问题:C# ContentProcessorContext.AddOutputFile方法的具体用法?C# ContentProcessorContext.AddOutputFile怎么用?C# ContentProcessorContext.AddOutputFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentProcessorContext的用法示例。


在下文中一共展示了ContentProcessorContext.AddOutputFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public override SongContent Process(AudioContent input, ContentProcessorContext context)
        {
            // Fallback if we aren't buiding for iOS.
            var platform = ContentHelper.GetMonoGamePlatform();
            if (platform != MonoGamePlatform.iOS && platform != MonoGamePlatform.Linux)
                return base.Process(input, context);

            //TODO: If quality isn't best and it's a .wma, don't compress to MP3. Leave it as a .wav instead
            string outputType = (platform == MonoGamePlatform.iOS) ? "mp3" : "wav";
            string outputFilename = Path.ChangeExtension(context.OutputFilename, outputType);
            string directoryName = Path.GetDirectoryName(outputFilename);
            if (!Directory.Exists(directoryName))
                Directory.CreateDirectory(directoryName);

            var inputFilename = Path.GetFullPath(input.FileName);

            // XNA's songprocessor converts the bitrate on the input file based 
            // on it's conversion quality. 
            //http://blogs.msdn.com/b/etayrien/archive/2008/09/22/audio-input-and-output-formats.aspx
            int desiredOutputBitRate = 0;
            switch (this.Quality)
            {
                case ConversionQuality.Low:
                    desiredOutputBitRate = 96000;
                    break;

                case ConversionQuality.Medium:
                    desiredOutputBitRate = 128000;
                    break;

                case ConversionQuality.Best:
                    desiredOutputBitRate = 192000;
                    break;
            }

            AudioFileType target = (platform == MonoGamePlatform.iOS) ? AudioFileType.Mp3 : AudioFileType.Wav;
            // Create a new file if we need to.
            FileStream outputStream = input.FileType != target ? new FileStream(outputFilename, FileMode.Create) : null;
            
            if (input.FileType != target)
                AudioConverter.ConvertFile(inputFilename, outputStream, target, desiredOutputBitRate,
                            input.Format.BitsPerSample, input.Format.ChannelCount);
            else
                File.Copy(inputFilename, outputFilename, true);

            if (outputStream != null)
                outputStream.Close();

            context.AddOutputFile(outputFilename);

            // SoundEffectContent is a sealed class, construct it using reflection
            var type = typeof(SongContent);
            ConstructorInfo c = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance,
                    null, new Type[] { typeof(string), typeof(int) }, null);

            var outputSongContent = (SongContent)c.Invoke(new Object[] { Path.GetFileName(outputFilename), (int)input.Duration.TotalMilliseconds });

            return outputSongContent;
        }
开发者ID:Boerlam001,项目名称:MonoGame,代码行数:59,代码来源:MGSongProcessor.cs

示例2: WriteTexture

        internal static void WriteTexture(object spriteFontContent, bool alphaOnly, ContentProcessorContext context, string filename)
        {
            dynamic sfc = ExposedObject.From(spriteFontContent);

            // Get a copy of the texture in Color format
            Texture2DContent originalTexture = sfc.Texture;
            BitmapContent originalBitmap = originalTexture.Mipmaps[0];
            PixelBitmapContent<Color> colorBitmap = new PixelBitmapContent<Color>(
                    originalBitmap.Width, originalBitmap.Height);
            BitmapContent.Copy(originalBitmap, colorBitmap);

            Bitmap bitmap = new Bitmap(colorBitmap.Width, colorBitmap.Height, PixelFormat.Format32bppArgb);
            for(int x = 0; x < colorBitmap.Width; x++) for(int y = 0; y < colorBitmap.Height; y++)
            {
                Color c = colorBitmap.GetPixel(x, y);
                if(alphaOnly)
                {
                    c.R = 255; c.G = 255; c.B = 255; // Undo premultiplication
                }
                bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B));
            }
            bitmap.Save(filename, ImageFormat.Png);
            bitmap.Dispose();

            context.AddOutputFile(filename);
        }
开发者ID:meds,项目名称:ChicksnVixens,代码行数:26,代码来源:FontShim.cs


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