ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Public Attributes | Properties | List of all members
ImageResizer.Resizing.ImageState Class Reference

Encapsulates the state of an image being resized. Can be used to simulate a resize as well as actually perform one. All code should ignore when Bitmaps and Graphics objects are null, and go about simulating all the mathematical functions as normal. More...

Inheritance diagram for ImageResizer.Resizing.ImageState:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Resizing.ImageState:
Collaboration graph
[legend]

Public Member Functions

 ImageState (ResizeSettings settings, Size originalSize, bool transparencySupported)
 
void ConvertIfCMYK ()
 If 'sourceBitmap' is CMYK and preRenderBitmap is null, converts sourceBitmap to RGB and stores in 'preRenderBitmap' More...
 
void EnsurePreRenderBitmap ()
 Clones 'sourceBitmap' into 'preRenderBitmap' if null. More...
 
void ApplyCropping ()
 Applies copyRect (if it will have any effect), placing the result in preRenderBitmap, and resetting copyRect More...
 
void EnsureRGBA ()
 Ensures that the working bitmap is in 32bpp RGBA format - otherwise it is converted. More...
 
void Dispose ()
 Disposes sourceBitmap, destGraphics, destBitmap, and copyAttributes if they are non-null More...
 

Public Attributes

ResizeSettings settings
 The commands to apply to the bitmap More...
 
Size originalSize
 The original size of the source bitmap. Use this instead of accessing the bitmap directly for this information, since the bitmap may not always be available More...
 
bool supportsTransparency = true
 Rendering choices can depend on whether the output format supports transparency. More...
 
LayoutBuilder layout = new LayoutBuilder()
 The layout object. Used for calculated and flowing the layout of the various rings around the image (padding, border, effect, margin, etc). More...
 
Size destSize
 The size of the target bitmap image. Set after all sizing operations have completed. More...
 
Size finalSize
 The dimensions of the bitmap afer all operations have been applied to it (Calling FlipRotate can change the bitmap dimensions). More...
 
RectangleF copyRect
 The rectangular portion of the source image to copy More...
 
Bitmap sourceBitmap
 The source bitmap. If null, skip drawing commands, but continue layout logic. More...
 
Bitmap preRenderBitmap
 An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets rendered to destBitmap. If defined, it should be used instead of sourceBitmap during RenderImage(), and disposed immediately after use. More...
 
Bitmap destBitmap
 The destination bitmap. If null, skip drawing commands, but continue layout logic. More...
 
Graphics destGraphics
 A graphics object to write to the destination bitmap. If null, skip drawing commands, but continue layout logic. More...
 
ImageAttributes copyAttibutes
 Allows color correction/modification during the image copy. More...
 

Properties

SizeF copySize [get]
 (read-only) Same as copyRect.Size, convenience property. More...
 
Dictionary< string, object > Data [get]
 Allows extensions to store data along with the image state More...
 

Detailed Description

Encapsulates the state of an image being resized. Can be used to simulate a resize as well as actually perform one. All code should ignore when Bitmaps and Graphics objects are null, and go about simulating all the mathematical functions as normal.

Definition at line 15 of file ImageState.cs.

Member Function Documentation

void ImageResizer.Resizing.ImageState.ApplyCropping ( )
inline

Applies copyRect (if it will have any effect), placing the result in preRenderBitmap, and resetting copyRect

Definition at line 99 of file ImageState.cs.

Referenced by ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.PreRenderImage().

99  {
100  ConvertIfCMYK();
101  var latest = preRenderBitmap ?? sourceBitmap;
102  if (latest == null || copyRect.IsEmpty) return;
103  if (copyRect.X == 0 && copyRect.Y == 0 && copyRect.Width == latest.Width && copyRect.Height == latest.Height) return;
104  try{
105  preRenderBitmap = latest.Clone(copyRect, PixelFormat.Format32bppArgb);
106  copyRect = new RectangleF(0, 0, preRenderBitmap.Width, preRenderBitmap.Height);
107  }finally{
108  if (latest != sourceBitmap)
109  {
110  latest.Dispose();
111  }
112  }
113 
114  }
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
void ConvertIfCMYK()
If &#39;sourceBitmap&#39; is CMYK and preRenderBitmap is null, converts sourceBitmap to RGB and stores in &#39;pr...
Definition: ImageState.cs:76
Bitmap preRenderBitmap
An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets ren...
Definition: ImageState.cs:71
RectangleF copyRect
The rectangular portion of the source image to copy
Definition: ImageState.cs:57
void ImageResizer.Resizing.ImageState.ConvertIfCMYK ( )
inline

If 'sourceBitmap' is CMYK and preRenderBitmap is null, converts sourceBitmap to RGB and stores in 'preRenderBitmap'

Definition at line 76 of file ImageState.cs.

76  {
77  if (preRenderBitmap == null && GetColorFormat(sourceBitmap) == ImageColorFormat.Cmyk) {
78  //For CMYK images, we must use DrawImage instead.
79  preRenderBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format24bppRgb);
80  using (var g = Graphics.FromImage(preRenderBitmap)) {
81  g.DrawImageUnscaled(sourceBitmap, 0, 0);
82  }
83  }
84  }
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
void ImageResizer.Resizing.ImageState.Dispose ( )
inline

Disposes sourceBitmap, destGraphics, destBitmap, and copyAttributes if they are non-null

Definition at line 202 of file ImageState.cs.

202  {
203  try {
204  //Close the source file stream if tagged for disposal.
205  if (sourceBitmap != null) {
206  if (sourceBitmap.Tag != null && sourceBitmap.Tag is BitmapTag) {
207  System.IO.Stream s = ((BitmapTag)sourceBitmap.Tag).Source;
208  if (s != null) s.Dispose();
209  }
210  sourceBitmap.Dispose();
211  }
212  } finally {
213  try {
214  if (destGraphics != null) destGraphics.Dispose();
215  } finally {
216  try {
217  if (destBitmap != null) destBitmap.Dispose();
218  } finally {
219  try {
220  if (copyAttibutes != null) copyAttibutes.Dispose();
221  } finally {
222  if (preRenderBitmap != null) preRenderBitmap.Dispose();
223  }
224  }
225  }
226 
227  }
228  }
Graphics destGraphics
A graphics object to write to the destination bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:182
Bitmap destBitmap
The destination bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:178
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
ImageAttributes copyAttibutes
Allows color correction/modification during the image copy.
Definition: ImageState.cs:186
Bitmap preRenderBitmap
An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets ren...
Definition: ImageState.cs:71
void ImageResizer.Resizing.ImageState.EnsurePreRenderBitmap ( )
inline

Clones 'sourceBitmap' into 'preRenderBitmap' if null.

Definition at line 89 of file ImageState.cs.

89  {
90  ConvertIfCMYK();
91  if (preRenderBitmap == null){
92  preRenderBitmap = sourceBitmap.Clone(new Rectangle(new Point(0, 0), sourceBitmap.Size), sourceBitmap.PixelFormat == PixelFormat.Format24bppRgb ? PixelFormat.Format24bppRgb : PixelFormat.Format32bppArgb);
93  }
94  }
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
void ConvertIfCMYK()
If &#39;sourceBitmap&#39; is CMYK and preRenderBitmap is null, converts sourceBitmap to RGB and stores in &#39;pr...
Definition: ImageState.cs:76
Bitmap preRenderBitmap
An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets ren...
Definition: ImageState.cs:71
void ImageResizer.Resizing.ImageState.EnsureRGBA ( )
inline

Ensures that the working bitmap is in 32bpp RGBA format - otherwise it is converted.

Definition at line 118 of file ImageState.cs.

119  {
120  ConvertIfCMYK();
121  var latest = preRenderBitmap ?? sourceBitmap;
122  if (latest.PixelFormat != PixelFormat.Format32bppArgb){
123  try{
124  preRenderBitmap = latest.Clone(new Rectangle(new Point(0, 0), latest.Size), PixelFormat.Format32bppArgb);
125  } finally{
126  if (latest != sourceBitmap) latest.Dispose();
127  }
128  }
129  }
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
void ConvertIfCMYK()
If &#39;sourceBitmap&#39; is CMYK and preRenderBitmap is null, converts sourceBitmap to RGB and stores in &#39;pr...
Definition: ImageState.cs:76
Bitmap preRenderBitmap
An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets ren...
Definition: ImageState.cs:71

Member Data Documentation

ImageAttributes ImageResizer.Resizing.ImageState.copyAttibutes
RectangleF ImageResizer.Resizing.ImageState.copyRect
Bitmap ImageResizer.Resizing.ImageState.destBitmap
Graphics ImageResizer.Resizing.ImageState.destGraphics
Size ImageResizer.Resizing.ImageState.destSize
Size ImageResizer.Resizing.ImageState.finalSize

The dimensions of the bitmap afer all operations have been applied to it (Calling FlipRotate can change the bitmap dimensions).

Definition at line 51 of file ImageState.cs.

Referenced by ImageResizer.ImageBuilder.ProcessFinalBitmap().

LayoutBuilder ImageResizer.Resizing.ImageState.layout = new LayoutBuilder()
Size ImageResizer.Resizing.ImageState.originalSize

The original size of the source bitmap. Use this instead of accessing the bitmap directly for this information, since the bitmap may not always be available

Definition at line 30 of file ImageState.cs.

Referenced by ImageResizer.Plugins.CropAround.CropAroundPlugin.LayoutImage(), ImageResizer.Plugins.SeamCarving.SeamCarvingPlugin.LayoutImage(), ImageResizer.ImageBuilder.LayoutImage(), and ImageResizer.Plugins.RedEye.RedEyePlugin.PostRenderImage().

Bitmap ImageResizer.Resizing.ImageState.preRenderBitmap

An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets rendered to destBitmap. If defined, it should be used instead of sourceBitmap during RenderImage(), and disposed immediately after use.

Definition at line 71 of file ImageState.cs.

Referenced by ImageResizer.Plugins.FreeImageScaling.FreeImageScalingPlugin.PreRenderImage(), ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.PreRenderImage(), ImageResizer.Plugins.SeamCarving.SeamCarvingPlugin.PreRenderImage(), ImageResizer.Plugins.Basic.SpeedOrQuality.RenderImage(), and ImageResizer.ImageBuilder.RenderImage().

ResizeSettings ImageResizer.Resizing.ImageState.settings
Bitmap ImageResizer.Resizing.ImageState.sourceBitmap
bool ImageResizer.Resizing.ImageState.supportsTransparency = true

Rendering choices can depend on whether the output format supports transparency.

Definition at line 36 of file ImageState.cs.

Referenced by ImageResizer.ImageBuilder.RenderBackground().

Property Documentation

SizeF ImageResizer.Resizing.ImageState.copySize
get

(read-only) Same as copyRect.Size, convenience property.

Definition at line 61 of file ImageState.cs.

Dictionary<string, object> ImageResizer.Resizing.ImageState.Data
get

Allows extensions to store data along with the image state

Definition at line 192 of file ImageState.cs.

Referenced by ImageResizer.Plugins.WhitespaceTrimmer.WhitespaceTrimmerPlugin.PostLayoutImage(), and ImageResizer.Plugins.SeamCarving.SeamCarvingPlugin.PreRenderImage().


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