ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | List of all members
ImageResizer.Plugins.SimpleFilters.SimpleFilters Class Reference
Inheritance diagram for ImageResizer.Plugins.SimpleFilters.SimpleFilters:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.SimpleFilters.SimpleFilters:
Collaboration graph
[legend]

Public Member Functions

IPlugin Install (Configuration.Config c)
 
bool Uninstall (Configuration.Config c)
 
IEnumerable< string > GetSupportedQuerystringKeys ()
 If the plugin reads any values from the querystring, the names of the keys should be specified here. This information is required so that the HttpModule knows when to handle an image request. More...
 
- Public Member Functions inherited from ImageResizer.Resizing.AbstractImageProcessor
 AbstractImageProcessor ()
 Creates a new AbstractImageProcessor with no extensions More...
 
 AbstractImageProcessor (IEnumerable< BuilderExtension > extensions)
 Creates a new AbstractImageProcessor which will run the specified extensions with each method call. More...
 
virtual Bitmap DecodeStreamFailed (Stream s, ResizeSettings settings, string optionalPath)
 Extensions are executed until one extension returns a non-null value. This is taken to mean that the error has been resolved. Extensions should not throw an exception unless they wish to cause subsequent extensions to not execute. If extensions throw an ArgumentException or ExternalException, it will be wrapped in an ImageCorruptedException instance. If the Bitmap class is used for decoding, read gdi-bugs.txt and make sure you set b.Tag to new BitmapTag(optionalPath,stream); More...
 
virtual Bitmap DecodeStream (Stream s, ResizeSettings settings, string optionalPath)
 Extend this to support alternate image source formats. If the Bitmap class is used for decoding, read gdi-bugs.txt and make sure you set b.Tag to new BitmapTag(optionalPath,stream); More...
 
- Public Member Functions inherited from ImageResizer.Plugins.IPlugin
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...
 

Protected Member Functions

override RequestedAction PreRenderImage (ImageState s)
 Supporting rounded corners. More...
 
override RequestedAction PostCreateImageAttributes (ImageState s)
 Process.5(Render).8: The ImageAttributes instance exists and can be modified or replaced. More...
 
override RequestedAction PostRenderImage (ImageState s)
 Process.5(Render).11: After the image is drawn More...
 
- Protected Member Functions inherited from ImageResizer.Resizing.AbstractImageProcessor
virtual void PreLoadImage (ref object source, ref string path, ref bool disposeSource, ref ResizeSettings settings)
 Extend this to allow additional types of source objects to be accepted by transforming them into Bitmap instances. More...
 
virtual Stream GetStream (object source, ResizeSettings settings, ref bool disposeStream, out string path, out bool restoreStreamPosition)
 Extend this to allow additional types of source objects to be accepted by transforming them into Stream instances. First plugin to return a Stream wins. More...
 
virtual RequestedAction PostDecodeStream (ref Bitmap img, ResizeSettings settings)
 Extend this to modify the Bitmap instance after it has been decoded by DecodeStream or DecodeStreamFailed More...
 
virtual void PreAcquireStream (ref object dest, ResizeSettings settings)
 Extend this to allow additional types of destination objects to be accepted by transforming them into a stream. More...
 
virtual RequestedAction BuildJob (ImageResizer.ImageJob job)
 The method to override if you want to replace the entire pipeline. All Build() calls call this method first. Does nothing in ImageBuilder More...
 
virtual RequestedAction buildToStream (Bitmap source, Stream dest, ResizeSettings settings)
 Called for Build() calls that want the result encoded. (Not for Bitmap Build(source,settings) calls. Only override this method if you need to replace the behavior of image encoding and image processing together, such as adding support for resizing multi-page TIFF files or animated GIFs. More...
 
virtual Bitmap buildToBitmap (Bitmap source, ResizeSettings settings, bool transparencySupported)
 Most calls funnel through here. Default behavior configures an ImageState instance and calls Process(imageState); Shouldn't be overriden for any reason I can think of - use the appropriate virtual method under Process(). If an extension returns a Bitmap instance, it will be used instead of the default behavior. Does NOT dispose of 'source' or 'source's underlying stream. More...
 
virtual RequestedAction OnProcess (ImageState s)
 Process.0 First step of the Process() method. Can replace the entire Process method if RequestAction.Cancel is returned. Can be used to add points to translate (for image maps), and also to modify the settings More...
 
virtual RequestedAction PrepareSourceBitmap (ImageState s)
 Process.1 Switches the bitmap to the correct frame or page, and applies source flipping commands. More...
 
virtual RequestedAction PostPrepareSourceBitmap (ImageState s)
 Process.2 Extend this to apply any pre-processing to the source bitmap that needs to occur before Layout begins More...
 
virtual RequestedAction Layout (ImageState s)
 Process.3(Layout).0: This is the last point at which points to translate should be added. Only return RequestedAction.Cancel if you wish to replace the entire Layout sequence logic. More...
 
virtual RequestedAction FlipExistingPoints (ImageState s)
 Process.3(Layout).1: This is where the points in the layout are flipped the same way the source bitmap was flipped (unless their flags specify otherwise) More...
 
virtual RequestedAction LayoutImage (ImageState s)
 Process.3(Layout).2: Rings 'image' and 'imageArea' are added to the layout. More...
 
virtual RequestedAction PostLayoutImage (ImageState s)
 Process.3(Layout).3: Add rings here to insert them between the image area and the padding More...
 
virtual RequestedAction LayoutPadding (ImageState s)
 Process.3(Layout).4: Ring "padding" is added to the layout More...
 
virtual RequestedAction PostLayoutPadding (ImageState s)
 Process.3(Layout).5: Add rings here to insert them between the padding and the border More...
 
virtual RequestedAction LayoutBorder (ImageState s)
 Process.3(Layout).6: Ring "border" is added to the layout More...
 
virtual RequestedAction PostLayoutBorder (ImageState s)
 Process.3(Layout).7: Add rings here to insert them between the border and the effect rings More...
 
virtual RequestedAction LayoutEffects (ImageState s)
 Process.3(Layout).8: Effects such as 'shadow' are added here. More...
 
virtual RequestedAction PostLayoutEffects (ImageState s)
 Process.3(Layout).9: Add rings here to insert them between the effects and the margin More...
 
virtual RequestedAction LayoutMargin (ImageState s)
 Process.3(Layout).10: Margins are added to the layout More...
 
virtual RequestedAction PostLayoutMargin (ImageState s)
 Process.3(Layout).11: Add rings here to insert them around the margin. Rings will be outermost More...
 
virtual RequestedAction LayoutRotate (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout is rotated. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutRotate (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout is rotated. May be called anytime during Layout() More...
 
virtual RequestedAction LayoutNormalize (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout is normalized to 0,0. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutNormalize (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout is normalized. May be called anytime during Layout() More...
 
virtual RequestedAction LayoutRound (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout point values are rounded to integers. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutRound (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout point values are rounded to integers. May be called anytime during Layout() More...
 
virtual RequestedAction EndLayout (ImageState s)
 Process.3(Layout).12: Occurs once layout has finished. No more changes should occur to points or rings in the layout after this method. destSize is calculated here. More...
 
virtual RequestedAction PrepareDestinationBitmap (ImageState s)
 Process.4: The destination bitmap is created and sized based destSize. A graphics object is initialized for rendering. More...
 
virtual RequestedAction Render (ImageState s)
 Process.5(Render) Rendering. Do not return RequestedAction.Cancel unless you want to replace the entire rendering system. More...
 
virtual RequestedAction RenderBackground (ImageState s)
 Process.5(Render).1 The background color is rendered More...
 
virtual RequestedAction PostRenderBackground (ImageState s)
 Process.5(Render).2 After the background color is rendered More...
 
virtual RequestedAction RenderEffects (ImageState s)
 Process.5(Render).3 Effects (such as a drop shadow or outer glow) are rendered More...
 
virtual RequestedAction PostRenderEffects (ImageState s)
 Process.5(Render).4 After outer effects are rendered More...
 
virtual RequestedAction RenderPadding (ImageState s)
 Process.5(Render).5 Image padding is drawn More...
 
virtual RequestedAction PostRenderPadding (ImageState s)
 Process.5(Render).6 After image padding is drawn More...
 
virtual RequestedAction CreateImageAttribues (ImageState s)
 Process.5(Render).7: An ImageAttributes instance is created if it doesn't already exist. More...
 
virtual RequestedAction RenderImage (ImageState s)
 Process.5(Render).10: The image is copied to the destination parallelogram specified by ring 'image'. More...
 
virtual RequestedAction RenderBorder (ImageState s)
 Process.5(Render).12: The border is rendered More...
 
virtual RequestedAction PostRenderBorder (ImageState s)
 Process.5(Render).13: After the border is drawn More...
 
virtual RequestedAction PreRenderOverlays (ImageState s)
 Process.5(Render).14: Any last-minute changes before watermarking or overlays are applied More...
 
virtual RequestedAction RenderOverlays (ImageState s)
 Process.5(Render).15: Watermarks can be rendered here. All image processing should be done More...
 
virtual RequestedAction PreFlushChanges (ImageState s)
 Process.5(Render).16: Called before changes are flushed and the graphics object is destroyed. More...
 
virtual RequestedAction FlushChanges (ImageState s)
 Process.5(Render).17: Changes are flushed to the bitmap here and the graphics object is destroyed. More...
 
virtual RequestedAction PostFlushChanges (ImageState s)
 Process.5(Render).18: Changes have been flushed to the bitmap, but the final bitmap has not been flipped yet. More...
 
virtual RequestedAction ProcessFinalBitmap (ImageState s)
 Process.6: Non-rendering changes to the bitmap object occur here, such as flipping. The graphics object is unavailable. More...
 
virtual RequestedAction EndProcess (ImageState s)
 Process.7: Layout and rendering are both complete. More...
 

Additional Inherited Members

- Protected Attributes inherited from ImageResizer.Resizing.AbstractImageProcessor
volatile IEnumerable
< BuilderExtension
exts
 Contains the set of extensions that are called for every method. More...
 

Detailed Description

Definition at line 14 of file SimpleFilters.cs.

Member Function Documentation

IEnumerable<string> ImageResizer.Plugins.SimpleFilters.SimpleFilters.GetSupportedQuerystringKeys ( )
inline

If the plugin reads any values from the querystring, the names of the keys should be specified here. This information is required so that the HttpModule knows when to handle an image request.

Returns

Implements ImageResizer.Plugins.IQuerystringPlugin.

Definition at line 25 of file SimpleFilters.cs.

25  {
26  return new string[] { "filter", "s.grayscale", "s.overlay", "s.shift", "s.sepia", "s.alpha", "s.brightness", "s.contrast", "s.saturation", "s.invert","s.roundcorners" };
27  }
override RequestedAction ImageResizer.Plugins.SimpleFilters.SimpleFilters.PostCreateImageAttributes ( ImageState  s)
inlineprotectedvirtual

Process.5(Render).8: The ImageAttributes instance exists and can be modified or replaced.

Parameters
s

Reimplemented from ImageResizer.Resizing.AbstractImageProcessor.

Definition at line 88 of file SimpleFilters.cs.

88  {
89  if (s.copyAttibutes == null) return RequestedAction.None;
90 
92 
93  List<float[][]> filters = new List<float[][]>();
94 
95  string filter = s.settings["filter"];
96  if (!string.IsNullOrEmpty(filter)) {
97  int valuesStart = filter.IndexOf('(');
98  string valStr = null;
99  double[] values = null;
100  if (valuesStart > -1) {
101  valStr = filter.Substring(valuesStart);
102  filter = filter.Substring(0, valuesStart);
103  values = ParseUtils.ParseList<double>(valStr, 0,0,1);
104  }
105 
106  if ("grayscale".Equals(filter, StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleFlat());
107  if ("sepia".Equals(filter, StringComparison.OrdinalIgnoreCase)) filters.Add(Sepia());
108  if (values != null && values.Length == 1) {
109  if ("alpha".Equals(filter, StringComparison.OrdinalIgnoreCase)) filters.Add(Alpha((float)values[0]));
110  if ("brightness".Equals(filter, StringComparison.OrdinalIgnoreCase)) filters.Add(Brightness((float)values[0]));
111  }
112  }
113  if ("true".Equals(s.settings["s.grayscale"], StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleNTSC());
114  if ("flat".Equals(s.settings["s.grayscale"], StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleFlat());
115  if ("y".Equals(s.settings["s.grayscale"], StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleY());
116  if ("ry".Equals(s.settings["s.grayscale"], StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleRY());
117  if ("ntsc".Equals(s.settings["s.grayscale"], StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleNTSC());
118  if ("bt709".Equals(s.settings["s.grayscale"], StringComparison.OrdinalIgnoreCase)) filters.Add(GrayscaleBT709());
119 
120  if ("true".Equals(s.settings["s.sepia"], StringComparison.OrdinalIgnoreCase)) filters.Add(Sepia());
121  if ("true".Equals(s.settings["s.invert"], StringComparison.OrdinalIgnoreCase)) filters.Add(Invert());
122 
123  Color? c = Util.ParseUtils.ParseColor(s.settings["s.shift"]);
124 
125  if (c != null) filters.Add(Shift(c.Value));
126 
127  string alpha = s.settings["s.alpha"];
128  string brightness = s.settings["s.brightness"];
129  string contrast = s.settings["s.contrast"];
130  string saturation = s.settings["s.saturation"];
131 
132  double temp = 0;
133  if (!string.IsNullOrEmpty(alpha) && double.TryParse(alpha, ParseUtils.FloatingPointStyle, NumberFormatInfo.InvariantInfo, out temp)) filters.Add(Alpha((float)temp));
134  if (!string.IsNullOrEmpty(brightness) && double.TryParse(brightness, ParseUtils.FloatingPointStyle, NumberFormatInfo.InvariantInfo, out temp)) filters.Add(Brightness((float)temp));
135  if (!string.IsNullOrEmpty(contrast) && double.TryParse(contrast, ParseUtils.FloatingPointStyle, NumberFormatInfo.InvariantInfo, out temp)) filters.Add(Contrast((float)temp));
136  if (!string.IsNullOrEmpty(saturation) && double.TryParse(saturation, ParseUtils.FloatingPointStyle, NumberFormatInfo.InvariantInfo, out temp)) filters.Add(Saturation((float)temp));
137 
138 
139  if (filters.Count == 0) return RequestedAction.None;
140  if (filters.Count == 1) s.copyAttibutes.SetColorMatrix(new ColorMatrix(filters[0]));
141  else {
142  //Multiple all the filters
143  float[][] first = filters[0];
144 
145  for (int i = 1; i < filters.Count; i++) {
146  first = Multiply(first, filters[i]);
147  }
148  s.copyAttibutes.SetColorMatrix(new ColorMatrix(first));
149 
150  }
151 
152 
153  return RequestedAction.None;
154  }
RequestedAction
What to do about remaining handlers/methods for the specified section
IEnumerable< string > GetSupportedQuerystringKeys()
If the plugin reads any values from the querystring, the names of the keys should be specified here...
ResizeSettings settings
The commands to apply to the bitmap
Definition: ImageState.cs:25
bool WasOneSpecified(params string[] keys)
Returns true if any of the specified keys are present in this NameValueCollection ...
ImageAttributes copyAttibutes
Allows color correction/modification during the image copy.
Definition: ImageState.cs:186
override RequestedAction ImageResizer.Plugins.SimpleFilters.SimpleFilters.PostRenderImage ( ImageState  s)
inlineprotectedvirtual

Process.5(Render).11: After the image is drawn

Parameters
s

Reimplemented from ImageResizer.Resizing.AbstractImageProcessor.

Definition at line 157 of file SimpleFilters.cs.

157  {
158  Color? c = Util.ParseUtils.ParseColor(s.settings["s.overlay"]);
159 
160  if (c != null && s.destGraphics != null) {
161  using (var b = new SolidBrush(c.Value)) {
162  s.destGraphics.FillPolygon(b, s.layout["image"]);
163  }
164  }
165  return RequestedAction.None;
166  }
Graphics destGraphics
A graphics object to write to the destination bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:182
override RequestedAction ImageResizer.Plugins.SimpleFilters.SimpleFilters.PreRenderImage ( ImageState  s)
inlineprotectedvirtual

Supporting rounded corners.

Parameters
s
Returns

Reimplemented from ImageResizer.Resizing.AbstractImageProcessor.

Definition at line 34 of file SimpleFilters.cs.

34  {
35  if (s.sourceBitmap == null) return RequestedAction.None;
36  double[] vals = NameValueCollectionExtensions.GetList<double>(s.settings, "s.roundcorners",0,1,4);
37  if (vals == null) return RequestedAction.None;
38 
39  if (vals.Length == 1) vals = new double[]{vals[0],vals[0],vals[0],vals[0]};
40 
41  bool hasValue = false;
42  foreach (double d in vals) if (d > 0) hasValue = true;
43  if (!hasValue) return RequestedAction.None;
44 
45  Bitmap cropped = null;
46  try{
47  //Make sure cropping is applied, and use existing prerendered bitmap if present.
48  s.ApplyCropping();
49 
50  cropped = s.preRenderBitmap ?? s.sourceBitmap;
51 
52  s.preRenderBitmap = new Bitmap(cropped.Width,cropped.Height, PixelFormat.Format32bppArgb);
53 
54  int[] radius = new int[4];
55  //Radius percentages are 0-100, a percentage of the smaller of the width and height.
56  for (int i = 0; i < vals.Length; i++) radius[i] = (int)Math.Round(Math.Max(0,Math.Min(99.999,vals[i])) * ((double)Math.Min(s.preRenderBitmap.Width,s.preRenderBitmap.Height) / 100));
57 
58 
59  s.preRenderBitmap.MakeTransparent();
60  using (Graphics g = Graphics.FromImage(s.preRenderBitmap)) {
61  g.SmoothingMode = SmoothingMode.AntiAlias;
62  g.CompositingMode = CompositingMode.SourceOver;
63  g.CompositingQuality = CompositingQuality.HighQuality;
64  g.PixelOffsetMode = PixelOffsetMode.HighQuality;
65  using (TextureBrush tb = new TextureBrush(cropped))
66  using (GraphicsPath gp = new GraphicsPath(FillMode.Winding)) {
67  Rectangle bounds = new Rectangle(0, 0, s.preRenderBitmap.Width, s.preRenderBitmap.Height);
68  int[] angles = new int[]{180,270,0,90};
69  int[] xs = new int[]{bounds.X,bounds.Right - radius[1], bounds.Right - radius[2], bounds.X};
70  int[] ys = new int[]{bounds.Y,bounds.Y,bounds.Bottom - radius[2], bounds.Bottom - radius[3]};
71  for (int i =0; i < 4; i++){
72  if (radius[i] > 0){
73  gp.AddArc(xs[i],ys[i],radius[i],radius[i],angles[i],90);
74  }else{
75  gp.AddLine(xs[i],ys[i],xs[i],ys[i]);
76  }
77  }
78  g.FillPath(tb, gp);
79 
80  }
81  }
82  }finally{
83  if (cropped != null & cropped != s.sourceBitmap) cropped.Dispose();
84  }
85  return RequestedAction.None;
86  }
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
Bitmap preRenderBitmap
An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets ren...
Definition: ImageState.cs:71

The documentation for this class was generated from the following file: