using System;
using System.IO;
namespace PixelFormatConversion
{
class PixelFormatConversion
{
private static ValueTuple<Image, PfncFormat> GetImage(string fileName)
{
var imageSource =
Image.FromFile(fileName);
var imageFormatPair = new ValueTuple<Image, PfncFormat>(
Image.FromPixelFormat(imageSource.Size, pixelFormat), pixelFormat);
imageSource.CopyTo(imageFormatPair.Item1);
return imageFormatPair;
}
{
converter.
Execute(srcImage, dstImage);
return dstImage;
}
private static string ToString(PfncFormat pixelFormat)
{
return PfncFormatValue.ToString(pixelFormat);
}
private static void Save(
Image image,
string path)
{
Console.WriteLine($" Saved as: {path}");
}
static void Main(string[] args)
{
Console.WriteLine("As a source, a Bayer pattern image is given.");
const string baseName = "FruitBowl";
const string extension = ".bmp";
var srcImageFormatPair =
GetImage(Path.Combine(new string[] { SystemInfo.InstallPath, "Tutorial", baseName + "Bayer" + extension }));
Save(srcImageFormatPair.Item1, baseName + ToString(srcImageFormatPair.Item2) + extension);
Console.WriteLine("As the destination, an RGB format is given.");
Console.WriteLine("Create a pixel format converter.");
var converter = PixelFormatConverter.
Create(srcImageFormatPair.Item2, dstFormat);
Console.WriteLine("Convert the source to another.");
var dstImage = GetAnotherRepresentation(srcImageFormatPair.Item1, converter);
Console.WriteLine("Saving the converted image as a file.");
Save(dstImage, baseName + ToString(dstFormat) + extension);
}
}
}