本文整理匯總了C#中System.Drawing.Imaging.ImageCodecInfo類的典型用法代碼示例。如果您正苦於以下問題:C# ImageCodecInfo類的具體用法?C# ImageCodecInfo怎麽用?C# ImageCodecInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ImageCodecInfo類屬於System.Drawing.Imaging命名空間,在下文中一共展示了ImageCodecInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ResizeImage
static void ResizeImage(string SourceFile, string DestinationFile, ImageCodecInfo encoder, EncoderParameters parameters)
{
try
{
using (Image Source = Image.FromFile(SourceFile))
{
int NewWidth, NewHeight;
if (Source.Width > ResizeMaxPixels && Source.Width >= Source.Height)
{
NewWidth = ResizeMaxPixels;
NewHeight = (Source.Height * ResizeMaxPixels) / Source.Width;
using (Image Dest = ResizeImage(Source, NewWidth, NewHeight))
Dest.Save(DestinationFile, encoder, parameters);
}
else if (Source.Height > ResizeMaxPixels && Source.Height >= Source.Width)
{
NewWidth = (Source.Width * ResizeMaxPixels) / Source.Height;
NewHeight = ResizeMaxPixels;
using (Image Dest = ResizeImage(Source, NewWidth, NewHeight))
Dest.Save(DestinationFile, encoder, parameters);
}
else
{
// no need for resize
Source.Save(DestinationFile, encoder, parameters);
}
}
}
catch (Exception e)
{
File.Delete(DestinationFile); // make sure destination file doesn't exist anymore
Console.WriteLine("Error: " + e.Message);
}
}
示例2: ConvertFromMemory
private static ImageCodecInfo[] ConvertFromMemory(IntPtr memoryStart, int numCodecs)
{
ImageCodecInfo[] infoArray = new ImageCodecInfo[numCodecs];
for (int i = 0; i < numCodecs; i++)
{
IntPtr lparam = (IntPtr) (((long) memoryStart) + (Marshal.SizeOf(typeof(ImageCodecInfoPrivate)) * i));
ImageCodecInfoPrivate data = new ImageCodecInfoPrivate();
System.Drawing.UnsafeNativeMethods.PtrToStructure(lparam, data);
infoArray[i] = new ImageCodecInfo();
infoArray[i].Clsid = data.Clsid;
infoArray[i].FormatID = data.FormatID;
infoArray[i].CodecName = Marshal.PtrToStringUni(data.CodecName);
infoArray[i].DllName = Marshal.PtrToStringUni(data.DllName);
infoArray[i].FormatDescription = Marshal.PtrToStringUni(data.FormatDescription);
infoArray[i].FilenameExtension = Marshal.PtrToStringUni(data.FilenameExtension);
infoArray[i].MimeType = Marshal.PtrToStringUni(data.MimeType);
infoArray[i].Flags = (ImageCodecFlags) data.Flags;
infoArray[i].Version = data.Version;
infoArray[i].SignaturePatterns = new byte[data.SigCount][];
infoArray[i].SignatureMasks = new byte[data.SigCount][];
for (int j = 0; j < data.SigCount; j++)
{
infoArray[i].SignaturePatterns[j] = new byte[data.SigSize];
infoArray[i].SignatureMasks[j] = new byte[data.SigSize];
Marshal.Copy((IntPtr) (((long) data.SigMask) + (j * data.SigSize)), infoArray[i].SignatureMasks[j], 0, data.SigSize);
Marshal.Copy((IntPtr) (((long) data.SigPattern) + (j * data.SigSize)), infoArray[i].SignaturePatterns[j], 0, data.SigSize);
}
}
return infoArray;
}
示例3: ExportBitmapCommand
static ExportBitmapCommand()
{
foreach (ImageCodecInfo ici in ImageCodecInfo.GetImageEncoders())
{
_jpegEncoder = ici;
}
}
示例4: Form1
public Form1()
{
InitializeComponent();
connected=false;
encoderParams=new EncoderParameters();
encoderParams.Param[0]=new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,95L);
jpegCodec=ImageCodecInfo.GetImageEncoders().First(codec=>codec.MimeType=="image/jpeg");
}
示例5: Save
public void Save(FileStream fileStream, ImageCodecInfo encoder, int quality)
{
var encoderParams = new EncoderParameters(2);
encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, quality);
encoderParams.Param[1] = new EncoderParameter(Encoder.ColorDepth, 24L);
_bitmap.Save(fileStream, encoder, encoderParams);
fileStream.Close();
}
示例6: GetMapResponse
public GetMapResponse(Image image, ImageCodecInfo codecInfo)
{
if (image == null)
throw new ArgumentNullException("image");
if (codecInfo == null)
throw new ArgumentNullException("codecInfo");
_image = image;
_codecInfo = codecInfo;
}
示例7: DevicePresenter
static DevicePresenter()
{
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
for (int j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == "image/jpeg")
_codecInfo = encoders[j];
}
}
示例8: GetImageDecoders
public static ImageCodecInfo[] GetImageDecoders ()
{
Hashtable oldInfo = ImageCodec.Decoders;
ImageCodecInfo [] newInfo = new ImageCodecInfo [oldInfo.Count];
int i=0;
foreach (ImageCodecInfo codec in oldInfo.Values) {
newInfo [i++] = (ImageCodecInfo) codec.MemberwiseClone ();
}
return newInfo;
}
示例9: SaveImage
public static void SaveImage(Image image, string fileName, ImageCodecInfo jpgEncoder, EncoderParameters parameters)
{
RetryUtility.Retry(() => image.Save(fileName, jpgEncoder, parameters),
RetryUtility.kDefaultMaxRetryAttempts,
RetryUtility.kDefaultRetryDelay,
new HashSet<Type>
{
Type.GetType("System.IO.IOException"),
Type.GetType("System.Runtime.InteropServices.ExternalException")
});
}
示例10: AvatarBuilder
static AvatarBuilder()
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == ImageFormat.Jpeg.Guid)
{
jpegImageCodeInfo = codec;
}
}
}
示例11: setQuality
/// <summary>
/// 質量控製
/// </summary>
/// <param name="level">級別,1-100</param>
/// <param name="mimeType">圖片格式,</param>
private static void setQuality(int level, string mimeType)
{
var codecs = ImageCodecInfo.GetImageEncoders();
ici = null;
foreach (var codec in codecs)
{
if (codec.MimeType == "image/" + mimeType)
ici = codec;
}
ep = new EncoderParameters();
ep.Param[0] = new EncoderParameter(Encoder.Quality, level);
}
示例12: Check
static void Check (ImageCodecInfo e, ImageCodecInfo d, Guid FormatID, string CodecName, string DllName,
string FilenameExtension, ImageCodecFlags Flags, string FormatDescription,
string MimeType, int Version, int signatureLength, string mask, string pattern, string pattern2)
{
Regex extRegex = new Regex (@"^(\*\.\w+(;(\*\.\w+))*;)?"+
Regex.Escape (FilenameExtension)[email protected]"(;\*\.\w+(;(\*\.\w+))*)?$",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
if (e != null) {
Assert.AreEqual (FormatID, e.FormatID, "Encoder.FormatID");
Assert.IsTrue (e.CodecName.IndexOf (CodecName)>=0,
"Encoder.CodecName contains "+CodecName);
Assert.AreEqual (DllName, e.DllName, "Encoder.DllName");
Assert.IsTrue (extRegex.IsMatch (e.FilenameExtension),
"Encoder.FilenameExtension is a right list with "+FilenameExtension);
Assert.AreEqual (Flags, e.Flags, "Encoder.Flags");
Assert.IsTrue (e.FormatDescription.IndexOf (FormatDescription)>=0,
"Encoder.FormatDescription contains "+FormatDescription);
Assert.IsTrue (e.MimeType.IndexOf (MimeType)>=0,
"Encoder.MimeType contains "+MimeType);
Assert.AreEqual (signatureLength, e.SignatureMasks.Length, "Encoder.SignatureMasks.Length");
for (int i = 0; i < signatureLength; i++) {
Assert.AreEqual (mask, BitConverter.ToString (e.SignatureMasks[i]), String.Format ("Encoder.SignatureMasks[{0}]", i));
}
Assert.AreEqual (signatureLength, e.SignaturePatterns.Length, "Encoder.SignaturePatterns.Length");
Assert.AreEqual (pattern, BitConverter.ToString (e.SignaturePatterns[0]), "Encoder.SignaturePatterns[0]");
if (pattern2 != null)
Assert.AreEqual (pattern2, BitConverter.ToString (e.SignaturePatterns[1]), "Encoder.SignaturePatterns[1]");
}
if (d != null) {
Assert.AreEqual (FormatID, d.FormatID, "Decoder.FormatID");
Assert.IsTrue (d.CodecName.IndexOf (CodecName)>=0,
"Decoder.CodecName contains "+CodecName);
Assert.AreEqual (DllName, d.DllName, "Decoder.DllName");
Assert.IsTrue (extRegex.IsMatch (d.FilenameExtension),
"Decoder.FilenameExtension is a right list with "+FilenameExtension);
Assert.AreEqual (Flags, d.Flags, "Decoder.Flags");
Assert.IsTrue (d.FormatDescription.IndexOf (FormatDescription)>=0,
"Decoder.FormatDescription contains "+FormatDescription);
Assert.IsTrue (d.MimeType.IndexOf (MimeType)>=0,
"Decoder.MimeType contains "+MimeType);
Assert.AreEqual (signatureLength, d.SignatureMasks.Length, "Decoder.SignatureMasks.Length");
for (int i = 0; i < signatureLength; i++) {
Assert.AreEqual (mask, BitConverter.ToString (d.SignatureMasks[i]), String.Format ("Decoder.SignatureMasks[{0}]", i));
}
Assert.AreEqual (signatureLength, d.SignaturePatterns.Length, "Decoder.SignaturePatterns.Length");
Assert.AreEqual (pattern, BitConverter.ToString (d.SignaturePatterns[0]), "Decoder.SignaturePatterns[0]");
if (pattern2 != null)
Assert.AreEqual (pattern2, BitConverter.ToString (d.SignaturePatterns[1]), "Decoder.SignaturePatterns[1]");
}
}
示例13: ControllerHelpers
static ControllerHelpers()
{
_MaxWidth = int.Parse(ConfigurationManager.AppSettings["UploadFileMaxWidth"]);
_ThumbMaxWidth = int.Parse(ConfigurationManager.AppSettings["ThumbFileMaxWidth"]);
_UserImgFolder = ConfigurationManager.AppSettings["UserImageFolder"];
_JpegCodecInfo = ImageCodecInfo.GetImageEncoders().Where(codec => codec.MimeType == "image/jpeg").First();
var qualityEncoder = Encoder.Quality;
var quality = 100;
var ratio = new EncoderParameter(qualityEncoder, quality);
_EncoderParameters = new EncoderParameters(1);
_EncoderParameters.Param[0] = ratio;
}
示例14: Webcam
public Webcam(string ocu_ipAddress, CameraConfiguration config)
{
this.config = config;
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count < 1)
throw new Exception("No video input devices available");
if (!string.IsNullOrEmpty(config.DeviceName))
videoSource = new VideoCaptureDevice(config.DeviceName);
//videoSource = new VideoCaptureDevice(videoDevices[1].MonikerString);
else
{
videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
}
updateWorker = new Timer();
updateWorker.Elapsed += new ElapsedEventHandler(updateWorker_Elapsed);
FrameRate = config.RCU_To_OCU_Framerate;
JPEGQuality = config.JPEGQuality;
isActive = false;
jpegCodec = GetEncoderInfo("image/jpeg");
videoSource.DesiredFrameSize = new Size(320, 240);
videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
udp_sender = new Comms.UDP_Sender(ocu_ipAddress, config.SendPort);
raw_frame_queue = new Utility.UpdateQueue<byte[]>(-1);
}
示例15: LzwCompression
public LzwCompression(int Quality)
{
this.parameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)Quality);
this.encoderInfo = GetEncoderInfo("image/jpeg");
this.encoderParams = new EncoderParameters(2);
this.encoderParams.Param[0] = parameter;
this.encoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)2);
}