Provides basic encoding functionality for Jpeg, png, and gif output. Allows adjustable Jpeg compression, but doesn't implement indexed PNG files or quantized GIF files.
More...
|
| DefaultEncoder (ImageFormat outputFormat) |
|
| DefaultEncoder (ImageFormat outputFormat, int jpegQuality) |
|
| DefaultEncoder (ResizeSettings settings, object original) |
|
virtual IEncoder | CreateIfSuitable (ResizeSettings settings, object original) |
| If the encoder can handle the requirements specified by 'settings' and 'source', it should return an encoder instance. If not, it should return null. More...
|
|
bool | IsValidOutputFormat (ImageFormat f) |
| Returns true if the this encoder supports the specified image format More...
|
|
void | Write (Image image, System.IO.Stream s) |
| Writes the specified image to the stream using Quality and OutputFormat More...
|
|
virtual IEnumerable< string > | GetSupportedQuerystringKeys () |
| Returns the querystring keys used by DefaultEncoder (quality, format, and thumbnail) More...
|
|
IPlugin | Install (Configuration.Config c) |
|
bool | Uninstall (Configuration.Config c) |
|
IEnumerable< FileSignature > | GetSignatures () |
| Returns signatures for jpeg, bmp, gif, png, wmf, ico, and tif More...
|
|
void | Write (Image i, Stream s) |
| Encodes the image to the specified stream More...
|
|
IPlugin | Install (Config c) |
| Installs the plugin in the specified Config instance. The plugin must handle all the work of loading settings, registering the plugin etc. More...
|
|
bool | Uninstall (Config c) |
| Uninstalls the plugin. Should reverse all changes made during Install More...
|
|
|
static ImageFormat | GetRequestedFormat (string format, ImageFormat defaultValue) |
| Tries to parse an ImageFormat from the settings.Format value. If an unrecogized format is specified, returns null. If an unsupported format is specified, it is returned. If no format is specified, returns defaultValue. More...
|
|
static ImageFormat | GetOriginalFormat (object original) |
| Attempts to determine the ImageFormat of the source image. First attempts to parse the path, if a string is present in original.Tag. (or if 'original' is a string) Falls back to using original.RawFormat. Returns null if both 'original' is null. RawFormat has a bad reputation, so this may return unexpected values, like MemoryBitmap or something in some situations. More...
|
|
static ImageFormat | GetImageFormatFromPhysicalPath (string path) |
| Returns the ImageFormat enumeration value based on the extension in the specified physical path. Extensions can lie, just a guess. More...
|
|
static string | GetExtensionFromImageFormat (ImageFormat format) |
| Returns an string instance from the specfied ImageFormat. First matching entry in imageExtensions is used. Returns null if not recognized. More...
|
|
static ImageFormat | GetImageFormatFromExtension (string ext) |
| Returns an ImageFormat instance from the specfied file extension. Extensions lie sometimes, just a guess. returns null if not recognized. More...
|
|
static void | AddImageExtension (string extension, ImageFormat matchingFormat) |
|
static string | GetContentTypeFromImageFormat (ImageFormat format) |
| Supports Png, Jpeg, Gif, Bmp, and Tiff. Throws a ArgumentOutOfRangeException if not png, jpeg, gif, bmp, or tiff More...
|
|
static ImageCodecInfo | GetImageCodeInfo (string mimeType) |
| Returns the first ImageCodeInfo instance with the specified mime type. Returns null if there are no matches. More...
|
|
static void | SaveJpeg (Image b, Stream target, int quality) |
| Saves the specified image to the specified stream using jpeg compression of the specified quality. More...
|
|
static void | SavePng (Image img, Stream target) |
|
static void | SaveBmp (Image img, Stream target) |
|
static void | SaveGif (Image img, Stream target) |
|
|
ImageFormat | OutputFormat [get, set] |
| If you set this to anything other than Gif, Png, or Jpeg, it will throw an exception. Defaults to Jpeg More...
|
|
int | Quality [get, set] |
| 0..100 value. The Jpeg compression quality. 90 is the best setting. Not relevant in Png or Gif compression More...
|
|
bool | SupportsTransparency [get] |
| Returns true if the desired output type supports transparency. More...
|
|
string | MimeType [get] |
| Returns the default mime-type for the OutputFormat More...
|
|
string | Extension [get] |
| Returns the default file extesnion for OutputFormat More...
|
|
bool | SupportsTransparency [get] |
| True if the output format will support transparency as it is currently configured. More...
|
|
string | MimeType [get] |
| Returns the appropriate mime-time for the output format as currently configured. More...
|
|
string | Extension [get] |
| Returns a file extension appropriate for the output format as currently configured, without a leading dot. More...
|
|
Provides basic encoding functionality for Jpeg, png, and gif output. Allows adjustable Jpeg compression, but doesn't implement indexed PNG files or quantized GIF files.
Definition at line 18 of file DefaultEncoder.cs.
virtual IEncoder ImageResizer.Plugins.Basic.DefaultEncoder.CreateIfSuitable |
( |
ResizeSettings |
settings, |
|
|
object |
original |
|
) |
| |
|
inlinevirtual |
If the encoder can handle the requirements specified by 'settings' and 'source', it should return an encoder instance. If not, it should return null.
- Parameters
-
settings | Request settings, like format, quality, colors, dither, etc. |
original | May be a Drawing.Image instance, a path, or null. To provide both, set Image.tag to the path. Helps the encoder detect the original format if the format was not specified. May also be used for palette generation hinting by some encoders. |
- Returns
Implements ImageResizer.Encoding.IEncoder.
Reimplemented in ImageResizer.Plugins.WicEncoder.WicEncoderPlugin, and ImageResizer.Plugins.WpfBuilder.WpfEncoderPlugin.
Definition at line 51 of file DefaultEncoder.cs.
54 return new DefaultEncoder(settings, original);
static ImageFormat GetRequestedFormat(string format, ImageFormat defaultValue)
Tries to parse an ImageFormat from the settings.Format value. If an unrecogized format is specified...
bool IsValidOutputFormat(ImageFormat f)
Returns true if the this encoder supports the specified image format
static string ImageResizer.Plugins.Basic.DefaultEncoder.GetContentTypeFromImageFormat |
( |
ImageFormat |
format | ) |
|
|
inlinestatic |
Supports Png, Jpeg, Gif, Bmp, and Tiff. Throws a ArgumentOutOfRangeException if not png, jpeg, gif, bmp, or tiff
- Parameters
-
- Returns
Definition at line 261 of file DefaultEncoder.cs.
263 if (format == null)
throw new ArgumentNullException();
265 if (ImageFormat.Png.Equals(format))
267 else if (ImageFormat.Jpeg.Equals(format))
269 else if (ImageFormat.Gif.Equals(format))
271 else if (ImageFormat.Bmp.Equals(format))
272 return "image/x-ms-bmp";
273 else if (ImageFormat.Tiff.Equals(format))
277 throw new ArgumentOutOfRangeException(
"Unsupported format " + format.ToString());
static string ImageResizer.Plugins.Basic.DefaultEncoder.GetExtensionFromImageFormat |
( |
ImageFormat |
format | ) |
|
|
inlinestatic |
Returns an string instance from the specfied ImageFormat. First matching entry in imageExtensions is used. Returns null if not recognized.
- Parameters
-
- Returns
Definition at line 184 of file DefaultEncoder.cs.
187 foreach (KeyValuePair<string, ImageFormat> p
in imageExtensions) {
188 if (p.Value.Guid.Equals(format.Guid))
return p.Key;
static ImageCodecInfo ImageResizer.Plugins.Basic.DefaultEncoder.GetImageCodeInfo |
( |
string |
mimeType | ) |
|
|
inlinestatic |
Returns the first ImageCodeInfo instance with the specified mime type. Returns null if there are no matches.
- Parameters
-
- Returns
Definition at line 287 of file DefaultEncoder.cs.
288 ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
289 foreach (ImageCodecInfo ici
in info)
290 if (ici.MimeType.Equals(mimeType, StringComparison.OrdinalIgnoreCase))
return ici;
static ImageFormat ImageResizer.Plugins.Basic.DefaultEncoder.GetImageFormatFromExtension |
( |
string |
ext | ) |
|
|
inlinestatic |
Returns an ImageFormat instance from the specfied file extension. Extensions lie sometimes, just a guess. returns null if not recognized.
- Parameters
-
- Returns
Definition at line 231 of file DefaultEncoder.cs.
233 if (
string.IsNullOrEmpty(ext))
return null;
235 ext = ext.Trim(
' ',
'.').ToLowerInvariant();
236 if (!imageExtensions.ContainsKey(ext))
return null;
237 return imageExtensions[ext];
static ImageFormat ImageResizer.Plugins.Basic.DefaultEncoder.GetImageFormatFromPhysicalPath |
( |
string |
path | ) |
|
|
inlinestatic |
Returns the ImageFormat enumeration value based on the extension in the specified physical path. Extensions can lie, just a guess.
- Parameters
-
- Returns
Definition at line 173 of file DefaultEncoder.cs.
static ImageFormat GetImageFormatFromExtension(string ext)
Returns an ImageFormat instance from the specfied file extension. Extensions lie sometimes, just a guess. returns null if not recognized.
static ImageFormat ImageResizer.Plugins.Basic.DefaultEncoder.GetOriginalFormat |
( |
object |
original | ) |
|
|
inlinestatic |
Attempts to determine the ImageFormat of the source image. First attempts to parse the path, if a string is present in original.Tag. (or if 'original' is a string) Falls back to using original.RawFormat. Returns null if both 'original' is null. RawFormat has a bad reputation, so this may return unexpected values, like MemoryBitmap or something in some situations.
- Parameters
-
original | The source image that was loaded from a stream, or a string path |
- Returns
Definition at line 149 of file DefaultEncoder.cs.
150 if (original == null)
return null;
152 string path = original as string;
154 if (path == null && original is Image) path = ((Image)original).Tag as string;
156 if (path == null && original is Image && ((Image)original).Tag is
BitmapTag) path = ((BitmapTag)((Image)original).Tag).Path;
160 ImageFormat f = DefaultEncoder.GetImageFormatFromPhysicalPath(path);
161 if (f != null)
return f;
164 if (original is Image)
return ((Image)original).RawFormat;
static ImageFormat ImageResizer.Plugins.Basic.DefaultEncoder.GetRequestedFormat |
( |
string |
format, |
|
|
ImageFormat |
defaultValue |
|
) |
| |
|
inlinestatic |
Tries to parse an ImageFormat from the settings.Format value. If an unrecogized format is specified, returns null. If an unsupported format is specified, it is returned. If no format is specified, returns defaultValue.
- Parameters
-
- Returns
Definition at line 132 of file DefaultEncoder.cs.
133 ImageFormat f = null;
134 if (!
string.IsNullOrEmpty(format)) {
135 f = DefaultEncoder.GetImageFormatFromExtension(format);
IEnumerable<FileSignature> ImageResizer.Plugins.Basic.DefaultEncoder.GetSignatures |
( |
| ) |
|
|
inline |
Returns signatures for jpeg, bmp, gif, png, wmf, ico, and tif
- Returns
Implements ImageResizer.Plugins.IFileSignatureProvider.
Definition at line 405 of file DefaultEncoder.cs.
409 new FileSignature(
new byte[] {0xFF, 0xD8, 0xFF},
"jpg",
"image/jpeg"),
410 new FileSignature(
new byte[] {0x42, 0x4D},
"bmp",
"image/x-ms-bmp"),
411 new FileSignature(
new byte[] {0x47,0x49,0x46, 0x38},
"gif",
"image/gif"),
412 new FileSignature(
new byte[] {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A},
"png",
"image/png"),
413 new FileSignature(
new byte[] {0xD7, 0xCD, 0xC6, 0x9A},
"wmf",
"image/x-wmf"),
414 new FileSignature(
new byte[] {0x00, 0x00,0x01, 0x00},
"ico",
"image/x-icon"),
415 new FileSignature(
new byte[] {0x49, 0x20, 0x49},
"tif",
"image/tiff"),
416 new FileSignature(
new byte[] {0x49, 0x49, 0x2A, 0x00},
"tif",
"image/tiff"),
417 new FileSignature(
new byte[] {0x4D, 0x4D, 0x00, 0x2A},
"tif",
"image/tiff"),
418 new FileSignature(
new byte[] {0x4D, 0x4D, 0x00, 0x2B},
"tif",
"image/tiff")
virtual IEnumerable<string> ImageResizer.Plugins.Basic.DefaultEncoder.GetSupportedQuerystringKeys |
( |
| ) |
|
|
inlinevirtual |
bool ImageResizer.Plugins.Basic.DefaultEncoder.IsValidOutputFormat |
( |
ImageFormat |
f | ) |
|
|
inline |
Returns true if the this encoder supports the specified image format
- Parameters
-
- Returns
Definition at line 73 of file DefaultEncoder.cs.
74 return (ImageFormat.Gif.Equals(f) || ImageFormat.Png.Equals(f) || ImageFormat.Jpeg.Equals(f));
static void ImageResizer.Plugins.Basic.DefaultEncoder.SaveJpeg |
( |
Image |
b, |
|
|
Stream |
target, |
|
|
int |
quality |
|
) |
| |
|
inlinestatic |
Saves the specified image to the specified stream using jpeg compression of the specified quality.
- Parameters
-
b | |
quality | A number between 0 and 100. Defaults to 90 if passed a negative number. Numbers over 100 are truncated to 100. 90 is a very good setting. |
target | |
Definition at line 303 of file DefaultEncoder.cs.
304 #region Encoder paramater notes
332 if (quality < 0) quality = 90;
333 if (quality > 100) quality = 100;
335 using (EncoderParameters p =
new EncoderParameters(1)) {
336 using (var ep =
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (
long)quality))
static ImageCodecInfo GetImageCodeInfo(string mimeType)
Returns the first ImageCodeInfo instance with the specified mime type. Returns null if there are no m...
static void ImageResizer.Plugins.Basic.DefaultEncoder.SavePng |
( |
Image |
img, |
|
|
Stream |
target |
|
) |
| |
|
inlinestatic |
Saves the image in png form. If Stream 'target' is not seekable, a temporary MemoryStream will be used to buffer the image data into the stream
- Parameters
-
Definition at line 350 of file DefaultEncoder.cs.
352 if (!target.CanSeek) {
354 using (MemoryStream ms =
new MemoryStream(4096)) {
355 img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
361 img.Save(target, System.Drawing.Imaging.ImageFormat.Png);
void ImageResizer.Plugins.Basic.DefaultEncoder.Write |
( |
Image |
image, |
|
|
System.IO.Stream |
s |
|
) |
| |
|
inline |
Writes the specified image to the stream using Quality and OutputFormat
- Parameters
-
Definition at line 92 of file DefaultEncoder.cs.
95 else if (ImageFormat.Gif.Equals(
OutputFormat)) SaveGif(image, s);
static void SaveJpeg(Image b, Stream target, int quality)
Saves the specified image to the specified stream using jpeg compression of the specified quality...
static void SavePng(Image img, Stream target)
ImageFormat OutputFormat
If you set this to anything other than Gif, Png, or Jpeg, it will throw an exception. Defaults to Jpeg
int Quality
0..100 value. The Jpeg compression quality. 90 is the best setting. Not relevant in Png or Gif compre...
string ImageResizer.Plugins.Basic.DefaultEncoder.Extension |
|
get |
Returns the default file extesnion for OutputFormat
Definition at line 116 of file DefaultEncoder.cs.
string ImageResizer.Plugins.Basic.DefaultEncoder.MimeType |
|
get |
Returns the default mime-type for the OutputFormat
Definition at line 110 of file DefaultEncoder.cs.
ImageFormat ImageResizer.Plugins.Basic.DefaultEncoder.OutputFormat |
|
getset |
If you set this to anything other than Gif, Png, or Jpeg, it will throw an exception. Defaults to Jpeg
Definition at line 61 of file DefaultEncoder.cs.
int ImageResizer.Plugins.Basic.DefaultEncoder.Quality |
|
getset |
0..100 value. The Jpeg compression quality. 90 is the best setting. Not relevant in Png or Gif compression
Definition at line 82 of file DefaultEncoder.cs.
bool ImageResizer.Plugins.Basic.DefaultEncoder.SupportsTransparency |
|
get |
Returns true if the desired output type supports transparency.
Definition at line 101 of file DefaultEncoder.cs.
The documentation for this class was generated from the following file: