本文整理匯總了C#中System.Drawing.Imaging.EncoderParameters.ConvertToMemory方法的典型用法代碼示例。如果您正苦於以下問題:C# EncoderParameters.ConvertToMemory方法的具體用法?C# EncoderParameters.ConvertToMemory怎麽用?C# EncoderParameters.ConvertToMemory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Imaging.EncoderParameters
的用法示例。
在下文中一共展示了EncoderParameters.ConvertToMemory方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SaveAdd
public void SaveAdd(Image image, EncoderParameters encoderParams) {
IntPtr encoder = IntPtr.Zero;
if (image == null) {
throw new ArgumentNullException("image");
}
if (encoderParams != null) {
encoder = encoderParams.ConvertToMemory();
}
rawData = null;
int status = SafeNativeMethods.Gdip.GdipSaveAddImage(new HandleRef(this, nativeImage), new HandleRef(image, image.nativeImage), new HandleRef(encoderParams, encoder));
if (encoder != IntPtr.Zero){
Marshal.FreeHGlobal(encoder);
}
if (status != SafeNativeMethods.Gdip.Ok) {
throw SafeNativeMethods.Gdip.StatusException(status);
}
}
示例2: Save
public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) {
if (stream == null){
throw new ArgumentNullException("stream");
}
if (encoder == null) {
throw new ArgumentNullException("encoder");
}
IntPtr encoderParamsMemory = IntPtr.Zero;
if (encoderParams != null) {
rawData = null;
encoderParamsMemory = encoderParams.ConvertToMemory();
}
int status = SafeNativeMethods.Gdip.Ok;
try {
Guid g = encoder.Clsid;
bool saved = false;
if (rawData != null) {
ImageCodecInfo rawEncoder = RawFormat.FindEncoder();
if (rawEncoder != null && rawEncoder.Clsid == g) {
stream.Write(rawData, 0, rawData.Length);
saved = true;
}
}
if (!saved) {
status = SafeNativeMethods.Gdip.GdipSaveImageToStream(new HandleRef(this, nativeImage),
new UnsafeNativeMethods.ComStreamFromDataStream(stream),
ref g,
new HandleRef(encoderParams, encoderParamsMemory));
}
}
finally {
if (encoderParamsMemory != IntPtr.Zero) {
Marshal.FreeHGlobal(encoderParamsMemory);
}
}
if (status != SafeNativeMethods.Gdip.Ok) {
throw SafeNativeMethods.Gdip.StatusException(status);
}
}
示例3: SaveAdd
public void SaveAdd(EncoderParameters encoderParams)
{
IntPtr zero = IntPtr.Zero;
if (encoderParams != null)
{
zero = encoderParams.ConvertToMemory();
}
this.rawData = null;
int status = SafeNativeMethods.Gdip.GdipSaveAdd(new HandleRef(this, this.nativeImage), new HandleRef(encoderParams, zero));
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
if (status != 0)
{
throw SafeNativeMethods.Gdip.StatusException(status);
}
}
示例4: Save
public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
if (encoder == null)
{
throw new ArgumentNullException("encoder");
}
System.Drawing.IntSecurity.DemandWriteFileIO(filename);
IntPtr zero = IntPtr.Zero;
if (encoderParams != null)
{
this.rawData = null;
zero = encoderParams.ConvertToMemory();
}
int status = 0;
try
{
Guid clsid = encoder.Clsid;
bool flag = false;
if (this.rawData != null)
{
ImageCodecInfo info = this.RawFormat.FindEncoder();
if ((info != null) && (info.Clsid == clsid))
{
using (FileStream stream = File.OpenWrite(filename))
{
stream.Write(this.rawData, 0, this.rawData.Length);
flag = true;
}
}
}
if (!flag)
{
status = SafeNativeMethods.Gdip.GdipSaveImageToFile(new HandleRef(this, this.nativeImage), filename, ref clsid, new HandleRef(encoderParams, zero));
}
}
finally
{
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
}
if (status != 0)
{
throw SafeNativeMethods.Gdip.StatusException(status);
}
}