@@ -84,7 +84,7 @@ private byte[] Binary
8484 using var stream = new MemoryStream ( ) ;
8585 IImageEncoder enc = GetDefaultImageExportEncoder ( ) ;
8686
87- _lazyImage . Value . First ( ) . Save ( stream , enc ) ;
87+ _lazyImage ? . Value . First ( ) . Save ( stream , enc ) ;
8888 _binary = stream . ToArray ( ) ;
8989 IsDirty = false ;
9090 }
@@ -127,7 +127,7 @@ public int Width
127127 {
128128 if ( ! _width . HasValue )
129129 {
130- _width = _lazyImage . Value . First ( ) . Width ;
130+ _width = _lazyImage ? . Value . First ( ) . Width ;
131131 }
132132 return _width . Value ;
133133 }
@@ -145,7 +145,7 @@ public int Height
145145 {
146146 if ( ! _height . HasValue )
147147 {
148- _height = _lazyImage . Value . First ( ) . Height ;
148+ _height = _lazyImage ? . Value . First ( ) . Height ;
149149 }
150150 return _height . Value ;
151151 }
@@ -365,16 +365,16 @@ public void ExportStream(
365365 IImageEncoder enc = GetDefaultImageExportEncoder ( format , lossy ) ;
366366 if ( enc is TiffEncoder )
367367 {
368- InternalSaveAsMultiPageTiff ( _lazyImage . Value , stream ) ;
368+ InternalSaveAsMultiPageTiff ( _lazyImage ? . Value , stream ) ;
369369 }
370370 else if ( enc is GifEncoder )
371371 {
372- InternalSaveAsMultiPageGif ( _lazyImage . Value , stream ) ;
372+ InternalSaveAsMultiPageGif ( _lazyImage ? . Value , stream ) ;
373373
374374 }
375375 else
376376 {
377- _lazyImage . Value . First ( ) . Save ( stream , enc ) ;
377+ _lazyImage ? . Value . First ( ) . Save ( stream , enc ) ;
378378 }
379379
380380 }
@@ -995,7 +995,7 @@ public int BitsPerPixel
995995 {
996996 if ( ! _bitsPerPixel . HasValue )
997997 {
998- _bitsPerPixel = _lazyImage . Value . First ( ) . PixelType . BitsPerPixel ;
998+ _bitsPerPixel = _lazyImage ? . Value . First ( ) . PixelType . BitsPerPixel ;
999999 }
10001000 return _bitsPerPixel . Value ;
10011001 }
@@ -1018,13 +1018,13 @@ public int FrameCount
10181018 {
10191019 if ( ! _frameCount . HasValue )
10201020 {
1021- if ( _lazyImage . Value . Count ( ) == 1 )
1021+ if ( _lazyImage ? . Value . Count ( ) == 1 )
10221022 {
1023- _frameCount = _lazyImage . Value . First ( ) . Frames . Count ;
1023+ _frameCount = _lazyImage ? . Value . First ( ) . Frames . Count ;
10241024 }
10251025 else
10261026 {
1027- _frameCount = _lazyImage . Value . Count ( ) ;
1027+ _frameCount = _lazyImage ? . Value . Count ( ) ;
10281028 }
10291029 }
10301030
@@ -1046,13 +1046,13 @@ public IEnumerable<AnyBitmap> GetAllFrames
10461046 {
10471047 get
10481048 {
1049- if ( _lazyImage . Value . Count ( ) == 1 )
1049+ if ( _lazyImage ? . Value . Count ( ) == 1 )
10501050 {
1051- return ImageFrameCollectionToImages ( _lazyImage . Value . First ( ) . Frames ) . Select ( x => ( AnyBitmap ) x ) ;
1051+ return ImageFrameCollectionToImages ( _lazyImage ? . Value . First ( ) . Frames ) . Select ( x => ( AnyBitmap ) x ) ;
10521052 }
10531053 else
10541054 {
1055- return _lazyImage . Value . Select ( x => ( AnyBitmap ) x ) ;
1055+ return _lazyImage ? . Value . Select ( x => ( AnyBitmap ) x ) ;
10561056 }
10571057 }
10581058 }
@@ -1138,7 +1138,7 @@ public byte[] ExtractAlphaData()
11381138
11391139 var alpha = new byte [ Width * Height ] ;
11401140
1141- switch ( _lazyImage . Value . First ( ) )
1141+ switch ( _lazyImage ? . Value . First ( ) )
11421142 {
11431143 case Image < Rgba32 > imageAsFormat :
11441144 imageAsFormat . ProcessPixelRows ( accessor =>
@@ -1464,7 +1464,7 @@ public void SetPixel(int x, int y, Color color)
14641464 /// </remarks>
14651465 public byte [ ] GetRGBBuffer ( )
14661466 {
1467- var image = _lazyImage . Value . First ( ) ;
1467+ var image = _lazyImage ? . Value . First ( ) ;
14681468 int width = image . Width ;
14691469 int height = image . Height ;
14701470 byte [ ] rgbBuffer = new byte [ width * height * 3 ] ; // 3 bytes per pixel (RGB)
@@ -1650,7 +1650,7 @@ public byte[] GetRGBBuffer()
16501650 /// </remarks>
16511651 public byte [ ] GetRGBABuffer ( )
16521652 {
1653- var image = _lazyImage . Value . First ( ) ;
1653+ var image = _lazyImage ? . Value . First ( ) ;
16541654 int width = image . Width ;
16551655 int height = image . Height ;
16561656 byte [ ] rgbBuffer = new byte [ width * height * 4 ] ; // 3 bytes per pixel (RGB)
@@ -1887,7 +1887,7 @@ private static Image CastToImageSharp(AnyBitmap bitmap)
18871887 }
18881888
18891889 //if it is loaded or gif/tiff
1890- var images = bitmap . _lazyImage . Value ;
1890+ var images = bitmap . _lazyImage ? . Value ;
18911891 if ( images . Count ( ) == 1 )
18921892 {
18931893 //not gif/tiff
@@ -1948,7 +1948,7 @@ private static Image<T> CastToImageSharp<T>(AnyBitmap bitmap) where T :unmanaged
19481948
19491949 }
19501950
1951- var images = bitmap . _lazyImage . Value ;
1951+ var images = bitmap . _lazyImage ? . Value ;
19521952 if ( images . Count ( ) == 1 )
19531953 {
19541954 if ( images . First ( ) is Image < T > correctType )
@@ -2597,7 +2597,7 @@ private void CreateNewImageInstance(int width, int height, Color backgroundColor
25972597 }
25982598 return [ image ] ;
25992599 } ) ;
2600- var _ = _lazyImage . Value ; // force load image
2600+ var _ = _lazyImage ? . Value ; // force load image
26012601 }
26022602
26032603 private void LoadImage ( Stream stream , bool preserveOriginalFormat )
@@ -3132,7 +3132,7 @@ private int GetStride(Image source = null)
31323132
31333133 private IntPtr GetFirstPixelData ( )
31343134 {
3135- var image = _lazyImage . Value . First ( ) ;
3135+ var image = _lazyImage ? . Value . First ( ) ;
31363136
31373137 if ( image is not Image < Rgba32 > )
31383138 {
@@ -3169,7 +3169,7 @@ private static void ConvertRGBAtoBGRA(byte[] data, int width, int height, int sa
31693169
31703170 private Color GetPixelColor ( int x , int y )
31713171 {
3172- switch ( _lazyImage . Value . First ( ) )
3172+ switch ( _lazyImage ? . Value . First ( ) )
31733173 {
31743174 case Image < Rgba32 > imageAsFormat :
31753175 return imageAsFormat [ x , y ] ;
@@ -3195,7 +3195,7 @@ private Color GetPixelColor(int x, int y)
31953195
31963196 //CloneAs() is expensive!
31973197 //Can throw out of memory exception, when this fucntion get called too much
3198- using ( Image < Rgb24 > converted = _lazyImage . Value . First ( ) . CloneAs < Rgb24 > ( ) )
3198+ using ( Image < Rgb24 > converted = _lazyImage ? . Value . First ( ) . CloneAs < Rgb24 > ( ) )
31993199 {
32003200 return converted [ x , y ] ;
32013201 }
@@ -3204,7 +3204,7 @@ private Color GetPixelColor(int x, int y)
32043204
32053205 private void SetPixelColor ( int x , int y , Color color )
32063206 {
3207- switch ( _lazyImage . Value . First ( ) )
3207+ switch ( _lazyImage ? . Value . First ( ) )
32083208 {
32093209 case Image < Rgba32 > imageAsFormat :
32103210 imageAsFormat [ x , y ] = color ;
@@ -3231,7 +3231,7 @@ private void SetPixelColor(int x, int y, Color color)
32313231 imageAsFormat [ x , y ] = color ;
32323232 break ;
32333233 default :
3234- ( _lazyImage . Value . First ( ) as Image < Rgba32 > ) [ x , y ] = color ;
3234+ ( _lazyImage ? . Value . First ( ) as Image < Rgba32 > ) [ x , y ] = color ;
32353235 break ;
32363236 }
32373237 IsDirty = true ;
@@ -3261,7 +3261,7 @@ private void LoadAndResizeImage(AnyBitmap original, int width, int height)
32613261 } ) ;
32623262
32633263 //force _lazyImage to load in this case
3264- var _ = _lazyImage . Value ;
3264+ var _ = _lazyImage ? . Value ;
32653265 }
32663266
32673267 private IImageEncoder GetDefaultImageExportEncoder ( ImageFormat format = ImageFormat . Default , int lossy = 100 )
@@ -3484,7 +3484,7 @@ private static void InternalSaveAsMultiPageGif(IEnumerable<Image> images, Stream
34843484 /// <returns>true if images is loaded (decoded) into the memory</returns>
34853485 public bool IsImageLoaded ( )
34863486 {
3487- return _lazyImage . IsValueCreated ;
3487+ return _lazyImage ? . IsValueCreated ;
34883488 }
34893489 }
34903490}
0 commit comments