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