@@ -30,6 +30,11 @@ public class ImageFactory : IDisposable
3030 /// </summary>
3131 private const int DefaultJpegQuality = 90 ;
3232
33+ /// <summary>
34+ /// The backup image format.
35+ /// </summary>
36+ private ImageFormat backupImageFormat ;
37+
3338 /// <summary>
3439 /// A value indicating whether this instance of the given entity has been disposed.
3540 /// </summary>
@@ -117,6 +122,7 @@ public ImageFactory Load(MemoryStream memoryStream)
117122
118123 // Set the other properties.
119124 this . JpegQuality = DefaultJpegQuality ;
125+ this . backupImageFormat = ImageFormat . Jpeg ;
120126 this . ImageFormat = ImageFormat . Jpeg ;
121127 this . ShouldProcess = true ;
122128
@@ -167,14 +173,47 @@ public ImageFactory Load(string imagePath)
167173
168174 // Set the other properties.
169175 this . JpegQuality = DefaultJpegQuality ;
170- this . ImageFormat = ImageUtils . GetImageFormat ( imageName ) ;
176+ ImageFormat imageFormat = ImageUtils . GetImageFormat ( imageName ) ;
177+ this . backupImageFormat = imageFormat ;
178+ this . ImageFormat = imageFormat ;
171179 this . ShouldProcess = true ;
172180 }
173181 }
174182
175183 return this ;
176184 }
177185
186+ /// <summary>
187+ /// Resets the ImageFactory to its original loaded state.
188+ /// </summary>
189+ /// <returns>
190+ /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
191+ /// </returns>
192+ public ImageFactory Reset ( )
193+ {
194+ if ( this . ShouldProcess )
195+ {
196+ MemoryStream memoryStream = ( MemoryStream ) this . Image . Tag ;
197+
198+ // Set our new image as the memorystream value.
199+ Image newImage = Image . FromStream ( memoryStream ) ;
200+
201+ // Store the stream in the image Tag property so we can dispose of it later.
202+ newImage . Tag = memoryStream ;
203+
204+ // Dispose and reassign the image.
205+ this . Image . Dispose ( ) ;
206+ this . Image = newImage ;
207+
208+ // Set the other properties.
209+ this . JpegQuality = DefaultJpegQuality ;
210+ this . ImageFormat = this . backupImageFormat ;
211+ }
212+
213+ return this ;
214+ }
215+
216+
178217 #region Manipulation
179218 /// <summary>
180219 /// Adds a query-string to the image factory to allow auto-processing of remote files.
@@ -441,7 +480,7 @@ public ImageFactory Rotate(RotateLayer rotateLayer)
441480 /// <returns>
442481 /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
443482 /// </returns>
444- public ImageFactory Saturate ( int percentage )
483+ public ImageFactory Saturation ( int percentage )
445484 {
446485 if ( this . ShouldProcess )
447486 {
@@ -451,7 +490,7 @@ public ImageFactory Saturate(int percentage)
451490 percentage = 0 ;
452491 }
453492
454- Saturate saturate = new Saturate { DynamicParameter = percentage } ;
493+ Saturation saturate = new Saturation { DynamicParameter = percentage } ;
455494
456495 this . Image = saturate . ProcessImage ( this ) ;
457496 }
@@ -504,7 +543,10 @@ public ImageFactory Watermark(TextLayer textLayer)
504543 /// Saves the current image to the specified file path.
505544 /// </summary>
506545 /// <param name="filePath">The path to save the image to.</param>
507- public void Save ( string filePath )
546+ /// <returns>
547+ /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
548+ /// </returns>
549+ public ImageFactory Save ( string filePath )
508550 {
509551 if ( this . ShouldProcess )
510552 {
@@ -527,16 +569,18 @@ public void Save(string filePath)
527569 ImageCodecInfo . GetImageEncoders ( ) . FirstOrDefault (
528570 ici => ici . MimeType . Equals ( "image/jpeg" , StringComparison . OrdinalIgnoreCase ) ) ;
529571
530- // ReSharper disable AssignNullToNotNullAttribute
572+ // ReSharper disable AssignNullToNotNullAttribute
531573 this . Image . Save ( filePath , imageCodecInfo , encoderParameters ) ;
532- // ReSharper restore AssignNullToNotNullAttribute
574+ // ReSharper restore AssignNullToNotNullAttribute
533575 }
534576 }
535577 else
536578 {
537579 this . Image . Save ( filePath , this . ImageFormat ) ;
538580 }
539581 }
582+
583+ return this ;
540584 }
541585
542586 /// <summary>
@@ -545,7 +589,10 @@ public void Save(string filePath)
545589 /// <param name="memoryStream">
546590 /// The <see cref="T:System.IO.MemoryStream"/> to save the image information to.
547591 /// </param>
548- public void Save ( MemoryStream memoryStream )
592+ /// <returns>
593+ /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
594+ /// </returns>
595+ public ImageFactory Save ( MemoryStream memoryStream )
549596 {
550597 if ( this . ShouldProcess )
551598 {
@@ -573,6 +620,8 @@ public void Save(MemoryStream memoryStream)
573620 this . Image . Save ( memoryStream , this . ImageFormat ) ;
574621 }
575622 }
623+
624+ return this ;
576625 }
577626
578627 #region IDisposable Members
0 commit comments