本文整理汇总了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;
}
示例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);
}