本文整理汇总了C#中System.Drawing.Imaging.EncoderParameter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# EncoderParameter.Dispose方法的具体用法?C# EncoderParameter.Dispose怎么用?C# EncoderParameter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Imaging.EncoderParameter
的用法示例。
在下文中一共展示了EncoderParameter.Dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RewriteImage
public static bool RewriteImage(Bitmap sourceBitmap, string saveFilePath)
{
if (sourceBitmap != null)
{
EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, 90L);
ImageCodecInfo jpegCodec = GetEncoderInfo("image/png");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
sourceBitmap.Save(saveFilePath, jpegCodec, encoderParams);
qualityParam.Dispose();
return true;
}
return false;
}
示例2: CreateThumbnail
public static void CreateThumbnail(string sourceFilename, string destFilename, int width, int height)
{
Image image = Image.FromFile(sourceFilename);
if ((image.Width <= width) && (image.Height <= height))
{
File.Copy(sourceFilename, destFilename, true);
image.Dispose();
}
else
{
int num = image.Width;
int num2 = image.Height;
float num3 = ((float)height) / ((float)num2);
if ((((float)width) / ((float)num)) < num3)
{
num3 = ((float)width) / ((float)num);
}
width = (int)(num * num3);
height = (int)(num2 * num3);
Image image2 = new Bitmap(width, height);
Graphics graphics = Graphics.FromImage(image2);
graphics.Clear(Color.White);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(image, new Rectangle(0, 0, width, height), new Rectangle(0, 0, num, num2), GraphicsUnit.Pixel);
EncoderParameters encoderParams = new EncoderParameters();
EncoderParameter parameter = new EncoderParameter(Encoder.Quality, 100L);
encoderParams.Param[0] = parameter;
ImageCodecInfo[] imageEncoders = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo encoder = null;
for (int i = 0; i < imageEncoders.Length; i++)
{
if (imageEncoders[i].FormatDescription.Equals("JPEG"))
{
encoder = imageEncoders[i];
break;
}
}
image2.Save(destFilename, encoder, encoderParams);
encoderParams.Dispose();
parameter.Dispose();
image.Dispose();
image2.Dispose();
graphics.Dispose();
}
}
示例3: Execute
public void Execute(CommandContext context)
{
Bitmap bitmap = null;
EncoderParameters encoderParams = null;
EncoderParameter parameter = null;
try
{
var temp = Environment.GetEnvironmentVariable("TEMP");
var picPath = temp + "\\" + Guid.NewGuid() + ".bmp";
var webcam = new WebCamUtility(context.Handle, 600, 480);
webcam.StartWebCam();
webcam.GrabImage(context.Handle, picPath);
webcam.CloseWebcam();
bitmap = new Bitmap(picPath);
var codecInfo = GetCodecInfo("image/jpeg");
var quality = Encoder.Quality;
encoderParams = new EncoderParameters(1);
const long num = 0x5fL;
parameter = new EncoderParameter(quality, num);
encoderParams.Param[0] = parameter;
var newPicPath = picPath.Replace("bmp", "jpg");
bitmap.Save(newPicPath, codecInfo, encoderParams);
if (context.SendPhotoByEmail)
{
SendComment(context, "#PCң����#���ڷ������WebCamץ�ĵ����ָ��Email�У����һ��ȥ���ա�");
SendPhotoByEmail(context, newPicPath);
}
else
{
SendComment(context, "#PCң����#�����ϴ����WebCamץ�ģ�һ�Ὣ�����������������С�");
context.WeiboService.SendWeiboWithPicture("������ʹ��#PCң����#�����ҵ�WebCamץ�� " + DateTime.Now.ToLongTimeString(), newPicPath);
}
}
finally
{
if (parameter != null) parameter.Dispose();
if (encoderParams != null) encoderParams.Dispose();
if (bitmap != null) bitmap.Dispose();
}
}
示例4: CompressionImage
public static byte[] CompressionImage(Stream fileStream, long quality)
{
using (System.Drawing.Image img = System.Drawing.Image.FromStream(fileStream))
{
using (Bitmap bitmap = new Bitmap(img))
{
ImageCodecInfo CodecInfo = GetEncoder(img.RawFormat);
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, quality);
myEncoderParameters.Param[0] = myEncoderParameter;
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, CodecInfo, myEncoderParameters);
myEncoderParameters.Dispose();
myEncoderParameter.Dispose();
return ms.ToArray();
}
}
}
}
示例5: CaptureWebPageBytesP
static byte[] CaptureWebPageBytesP(string body, int width, int height)
{
byte[] data;
using (WebBrowser web = new WebBrowser())
{
web.ScrollBarsEnabled = false; // no scrollbars
web.ScriptErrorsSuppressed = true; // no errors
web.DocumentText = body;
while (web.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
System.Windows.Forms.Application.DoEvents();
web.Width = web.Document.Body.ScrollRectangle.Width;
web.Height = web.Document.Body.ScrollRectangle.Height;
// a bitmap that we will draw to
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(web.Width, web.Height))
{
// draw the web browser to the bitmap
web.DrawToBitmap(bmp, new Rectangle(web.Location.X, web.Location.Y, web.Width, web.Height));
// draw the web browser to the bitmap
GraphicsUnit units = GraphicsUnit.Pixel;
RectangleF destRect = new RectangleF(0F, 0F, width, height);
RectangleF srcRect = new RectangleF(0, 0, web.Width, web.Width * 1.5F);
Bitmap b = new Bitmap(width, height);
Graphics g = Graphics.FromImage((Image)b);
g.Clear(Color.White);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bmp, destRect, srcRect, units);
g.Dispose();
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
EncoderParameter qualityParam = null;
EncoderParameters encoderParams = null;
try
{
ImageCodecInfo imageCodec = null;
imageCodec = GetEncoderInfo("image/jpeg");
qualityParam = new EncoderParameter(Encoder.Quality, 100L);
encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
b.Save(stream, imageCodec, encoderParams);
}
catch (Exception)
{
throw new Exception();
}
finally
{
if (encoderParams != null) encoderParams.Dispose();
if (qualityParam != null) qualityParam.Dispose();
}
b.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
data = new byte[stream.Length];
stream.Read(data, 0, (int)stream.Length);
}
}
}
return data;
}
示例6: SaveImage
protected override void SaveImage(Stream stream, Image image)
{
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo(EncoderType);
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(EncoderParameterCount);
myEncoderParameter = new EncoderParameter(myEncoder, imageQuality);
myEncoderParameters.Param[0] = myEncoderParameter;
try
{
image.Save(stream, myImageCodecInfo, myEncoderParameters);
}
finally
{
myEncoderParameters.Dispose();
myEncoderParameter.Dispose();
}
}
示例7: SaveJpegImage
private void SaveJpegImage(Stream stream, Image image)
{
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo(EncoderType);
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(EncoderParameterCount);
myEncoderParameter = new EncoderParameter(myEncoder, PluginSettings.ImageQuality);
myEncoderParameters.Param[0] = myEncoderParameter;
try
{
image.Save(stream, myImageCodecInfo, myEncoderParameters);
}
finally
{
myEncoderParameters.Dispose();
myEncoderParameter.Dispose();
}
}
示例8: MakeThumbnail
//.........这里部分代码省略.........
}
else
{
newwidth = originalImage.Width;
newheight = originalImage.Height;
}
}
}
towidth = newwidth;
toheight = newheight;
//config.Mode = ThumbnailMode.HeightAndWidth;
break;
default:
break;
}
config.Width = towidth;
config.Height = toheight;
//new Bitmap instance
Image bitmap = new Bitmap(towidth, toheight);
//new Graphics instance
Graphics g = Graphics.FromImage(bitmap);
//set InterpolationMode
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//set CompositingQuality
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
//set HighQuality ,low speed SmoothingMode
g.SmoothingMode = SmoothingMode.AntiAlias;
//clear the Graphics and fill with Transparent background color
if (config.IsPng)
g.Clear(Color.Transparent);
else
g.Clear(Color.White);
// render
g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel);
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs)
{
if (config.IsPng)
{
if (codec.MimeType.IndexOf("png") > -1)
{
ici = codec;
}
}
else
{
if (codec.MimeType.IndexOf("jpeg") > -1)
{
ici = codec;
}
}
}
var myEncoder = Encoder.Quality;
var myEncoderParameters = new EncoderParameters(1);
//ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
//ImageCodecInfo ici = null;
// 在这里设置图片的质量等级为95L.
var myEncoderParameter = new EncoderParameter(myEncoder, 95L);
myEncoderParameters.Param[0] = myEncoderParameter;
try
{
// System.Drawing.Imaging.ImageFormat.Jpeg
bitmap.Save(config.Path, ici, myEncoderParameters);
}
catch (System.Exception e)
{
throw e;
}
finally
{
myEncoderParameter.Dispose();
myEncoderParameters.Dispose();
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
}
示例9: CompressionImage
/// <summary>
/// 壓縮圖片 /// </summary>
/// <param name="fileStream">圖片流</param>
/// <param name="quality">壓縮質量0-100之間 數值越大質量越高</param>
/// <returns></returns>
public static byte[] CompressionImage(Image img, long quality)
{
using (Bitmap bitmap = new Bitmap(img))
{
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo CodecInfo = null;
for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
CodecInfo = arrayICI[x];
//設置jpg
break;
}
}
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, quality);
myEncoderParameters.Param[0] = myEncoderParameter;
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, CodecInfo, myEncoderParameters);
myEncoderParameters.Dispose();
myEncoderParameter.Dispose();
return ms.ToArray();
}
}
}