本文整理匯總了C#中SharpDX.WIC.ImagingFactory.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# ImagingFactory.Dispose方法的具體用法?C# ImagingFactory.Dispose怎麽用?C# ImagingFactory.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpDX.WIC.ImagingFactory
的用法示例。
在下文中一共展示了ImagingFactory.Dispose方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
/// <summary>
/// SharpDX WIC sample. Encode to JPG and decode.
/// </summary>
static void Main()
{
const int width = 512;
const int height = 512;
const string filename = "output.jpg";
var factory = new ImagingFactory();
WICStream stream = null;
// ------------------------------------------------------
// Encode a JPG image
// ------------------------------------------------------
// Create a WIC outputstream
if (File.Exists(filename))
File.Delete(filename);
stream = new WICStream(factory, filename, NativeFileAccess.Write);
// Initialize a Jpeg encoder with this stream
var encoder = new JpegBitmapEncoder(factory);
encoder.Initialize(stream);
// Create a Frame encoder
var bitmapFrameEncode = new BitmapFrameEncode(encoder);
bitmapFrameEncode.Options.ImageQuality = 0.8f;
bitmapFrameEncode.Initialize();
bitmapFrameEncode.SetSize(width, height);
var guid = PixelFormat.Format24bppBGR;
bitmapFrameEncode.SetPixelFormat(ref guid);
// Write a pseudo-plasma to a buffer
int stride = PixelFormat.GetStride(PixelFormat.Format24bppBGR, width);
var bufferSize = height * stride;
var buffer = new DataStream(bufferSize, true, true);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
buffer.WriteByte((byte)(x / 2.0 + 20.0 * Math.Sin(y / 40.0)));
buffer.WriteByte((byte)(y / 2.0 + 30.0 * Math.Sin(x / 80.0)));
buffer.WriteByte((byte)(x / 2.0));
}
}
// Copy the pixels from the buffer to the Wic Bitmap Frame encoder
bitmapFrameEncode.WritePixels(512, new DataRectangle(buffer.DataPointer, stride));
// Commit changes
bitmapFrameEncode.Commit();
encoder.Commit();
bitmapFrameEncode.Dispose();
encoder.Dispose();
stream.Dispose();
// ------------------------------------------------------
// Decode the previous JPG image
// ------------------------------------------------------
// Read input
stream = new WICStream(factory, filename, NativeFileAccess.Read);
var decoder = new JpegBitmapDecoder(factory);
decoder.Initialize(stream, DecodeOptions.CacheOnDemand);
var bitmapFrameDecode = decoder.GetFrame(0);
var queryReader = bitmapFrameDecode.MetadataQueryReader;
// Dump MetadataQueryreader
queryReader.Dump(Console.Out);
queryReader.Dispose();
bitmapFrameDecode.Dispose();
decoder.Dispose();
stream.Dispose();
// Dispose
factory.Dispose();
System.Diagnostics.Process.Start(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, filename)));
}