// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using SharpDX.Win32;
namespace SharpDX.WIC
{
public partial class BitmapEncoder
{
private ImagingFactory factory;
private WICStream internalWICStream;
///
/// Initializes a new instance of the class.
///
/// The factory.
/// The container format GUID. List from
/// HRESULT IWICImagingFactory::CreateEncoder([In] const GUID& guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)
public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid)
{
this.factory = factory;
factory.CreateEncoder(containerFormatGuid, null, this);
}
///
/// Initializes a new instance of the class.
///
/// The factory.
/// The container format GUID. List from
/// The GUID vendor ref.
/// HRESULT IWICImagingFactory::CreateEncoder([In] const GUID& guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)
public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid, System.Guid guidVendorRef)
{
this.factory = factory;
factory.CreateEncoder(containerFormatGuid, guidVendorRef, this);
}
///
/// Initializes a new instance of the class.
///
/// The factory.
/// The container format GUID. List from
/// A stream to use as the output of this bitmap encoder.
/// HRESULT IWICImagingFactory::CreateEncoder([In] const GUID& guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)
public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid, WICStream stream = null)
{
this.factory = factory;
factory.CreateEncoder(containerFormatGuid, null, this);
if (stream != null)
Initialize(stream);
}
///
/// Initializes a new instance of the class.
///
/// The factory.
/// The container format GUID. List from
/// A stream to use as the output of this bitmap encoder.
/// HRESULT IWICImagingFactory::CreateEncoder([In] const GUID& guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)
public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid, System.IO.Stream stream = null)
{
this.factory = factory;
factory.CreateEncoder(containerFormatGuid, null, this);
if (stream != null)
Initialize(stream);
}
///
/// Initializes a new instance of the class.
///
/// The factory.
/// The container format GUID. List from
/// The GUID vendor ref.
/// A stream to use as the output of this bitmap encoder.
/// HRESULT IWICImagingFactory::CreateEncoder([In] const GUID& guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)
public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid, System.Guid guidVendorRef, WICStream stream = null)
{
this.factory = factory;
factory.CreateEncoder(containerFormatGuid, guidVendorRef, this);
if (stream != null)
Initialize(stream);
}
///
/// Initializes a new instance of the class.
///
/// The factory.
/// The container format GUID. List from
/// The GUID vendor ref.
/// A stream to use as the output of this bitmap encoder.
/// HRESULT IWICImagingFactory::CreateEncoder([In] const GUID& guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)
public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid, System.Guid guidVendorRef, System.IO.Stream stream = null)
{
this.factory = factory;
factory.CreateEncoder(containerFormatGuid, guidVendorRef, this);
if (stream != null)
Initialize(stream);
}
///
/// Initializes the encoder with the provided stream.
///
/// The stream to use for initialization.
/// If the method succeeds, it returns . Otherwise, it throws an exception.
/// HRESULT IWICBitmapEncoder::Initialize([In, Optional] IStream* pIStream,[In] WICBitmapEncoderCacheOption cacheOption)
public void Initialize(IStream stream)
{
if (this.internalWICStream != null)
throw new InvalidOperationException("This instance is already initialized with an existing stream");
Initialize(stream, SharpDX.WIC.BitmapEncoderCacheOption.NoCache);
}
///
/// Initializes the encoder with the provided stream.
///
/// The stream to use for initialization.
/// If the method succeeds, it returns . Otherwise, it throws an exception.
/// HRESULT IWICBitmapEncoder::Initialize([In, Optional] IStream* pIStream,[In] WICBitmapEncoderCacheOption cacheOption)
public void Initialize(System.IO.Stream stream)
{
if (this.internalWICStream != null)
throw new InvalidOperationException("This instance is already initialized with an existing stream");
this.internalWICStream = new WICStream(factory, stream);
Initialize(this.internalWICStream, SharpDX.WIC.BitmapEncoderCacheOption.NoCache);
}
///
/// Sets the objects for the encoder.
///
/// The color contexts to set for the encoder.
/// If the method succeeds, it returns . Otherwise, it throws an exception.
/// HRESULT IWICBitmapEncoder::SetColorContexts([In] unsigned int cCount,[In, Buffer] IWICColorContext** ppIColorContext)
public void SetColorContexts(SharpDX.WIC.ColorContext[] colorContextOut)
{
SetColorContexts(colorContextOut != null ? colorContextOut.Length : 0, colorContextOut);
}
protected override unsafe void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
if (this.internalWICStream != null)
internalWICStream.Dispose();
internalWICStream = null;
}
}
}
}