@@ -4427,7 +4427,12 @@ public void Ping(byte[] data, IMagickReadSettings<QuantumType>? readSettings)
44274427 /// </summary>
44284428 /// <param name="file">The file to read the image from.</param>
44294429 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
4430- public void Ping ( FileInfo file ) => Ping ( file , null ) ;
4430+ public void Ping ( FileInfo file )
4431+ {
4432+ Throw . IfNull ( file ) ;
4433+
4434+ Ping ( file . FullName ) ;
4435+ }
44314436
44324437 /// <summary>
44334438 /// Reads only metadata and not the pixel data.
@@ -4439,7 +4444,7 @@ public void Ping(FileInfo file, IMagickReadSettings<QuantumType>? readSettings)
44394444 {
44404445 Throw . IfNull ( file ) ;
44414446
4442- Read ( file . FullName , readSettings , true ) ;
4447+ Ping ( file . FullName , readSettings ) ;
44434448 }
44444449
44454450 /// <summary>
@@ -4706,7 +4711,11 @@ public void Read(byte[] data, IMagickReadSettings<QuantumType>? readSettings)
47064711 /// <param name="file">The file to read the image from.</param>
47074712 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
47084713 public void Read ( FileInfo file )
4709- => Read ( file , null ) ;
4714+ {
4715+ Throw . IfNull ( file ) ;
4716+
4717+ Read ( file . FullName ) ;
4718+ }
47104719
47114720 /// <summary>
47124721 /// Read single image frame.
@@ -4732,7 +4741,7 @@ public void Read(FileInfo file, MagickFormat format)
47324741 {
47334742 Throw . IfNull ( file ) ;
47344743
4735- Read ( file . FullName , new MagickReadSettings ( _settings ) { Format = format } ) ;
4744+ Read ( file . FullName , format ) ;
47364745 }
47374746
47384747 /// <summary>
@@ -4843,7 +4852,11 @@ public void Read(string fileName, IMagickReadSettings<QuantumType>? readSettings
48434852 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
48444853 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
48454854 public Task ReadAsync ( FileInfo file )
4846- => ReadAsync ( file , CancellationToken . None ) ;
4855+ {
4856+ Throw . IfNull ( file ) ;
4857+
4858+ return ReadAsync ( file . FullName ) ;
4859+ }
48474860
48484861 /// <summary>
48494862 /// Read single image frame.
@@ -4853,7 +4866,11 @@ public Task ReadAsync(FileInfo file)
48534866 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
48544867 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
48554868 public Task ReadAsync ( FileInfo file , CancellationToken cancellationToken )
4856- => ReadAsync ( file , null , cancellationToken ) ;
4869+ {
4870+ Throw . IfNull ( file ) ;
4871+
4872+ return ReadAsync ( file . FullName , cancellationToken ) ;
4873+ }
48574874
48584875 /// <summary>
48594876 /// Read single image frame.
@@ -4863,7 +4880,11 @@ public Task ReadAsync(FileInfo file, CancellationToken cancellationToken)
48634880 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
48644881 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
48654882 public Task ReadAsync ( FileInfo file , MagickFormat format )
4866- => ReadAsync ( file , format , CancellationToken . None ) ;
4883+ {
4884+ Throw . IfNull ( file ) ;
4885+
4886+ return ReadAsync ( file . FullName , format ) ;
4887+ }
48674888
48684889 /// <summary>
48694890 /// Read single image frame.
@@ -4874,7 +4895,11 @@ public Task ReadAsync(FileInfo file, MagickFormat format)
48744895 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
48754896 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
48764897 public Task ReadAsync ( FileInfo file , MagickFormat format , CancellationToken cancellationToken )
4877- => ReadAsync ( file , new MagickReadSettings ( _settings ) { Format = format } , cancellationToken ) ;
4898+ {
4899+ Throw . IfNull ( file ) ;
4900+
4901+ return ReadAsync ( file . FullName , format , cancellationToken ) ;
4902+ }
48784903
48794904 /// <summary>
48804905 /// Read single image frame.
@@ -4884,7 +4909,11 @@ public Task ReadAsync(FileInfo file, MagickFormat format, CancellationToken canc
48844909 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
48854910 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
48864911 public Task ReadAsync ( FileInfo file , IMagickReadSettings < QuantumType > ? readSettings )
4887- => ReadAsync ( file , readSettings , CancellationToken . None ) ;
4912+ {
4913+ Throw . IfNull ( file ) ;
4914+
4915+ return ReadAsync ( file . FullName , readSettings ) ;
4916+ }
48884917
48894918 /// <summary>
48904919 /// Read single image frame.
@@ -5168,7 +5197,11 @@ public void ReadPixels(string fileName, IPixelReadSettings<QuantumType> settings
51685197 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
51695198 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
51705199 public Task ReadPixelsAsync ( FileInfo file , IPixelReadSettings < QuantumType > settings )
5171- => ReadPixelsAsync ( file , settings , CancellationToken . None ) ;
5200+ {
5201+ Throw . IfNull ( file ) ;
5202+
5203+ return ReadPixelsAsync ( file . FullName , settings ) ;
5204+ }
51725205
51735206 /// <summary>
51745207 /// Read single image frame from pixel data.
@@ -7141,8 +7174,10 @@ public void Write(FileInfo file)
71417174 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
71427175 public void Write ( FileInfo file , IWriteDefines defines )
71437176 {
7144- _settings . SetDefines ( defines ) ;
7145- Write ( file , defines . Format ) ;
7177+ Throw . IfNull ( file ) ;
7178+
7179+ Write ( file . FullName , defines ) ;
7180+ file . Refresh ( ) ;
71467181 }
71477182
71487183 /// <summary>
@@ -7153,8 +7188,10 @@ public void Write(FileInfo file, IWriteDefines defines)
71537188 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
71547189 public void Write ( FileInfo file , MagickFormat format )
71557190 {
7156- using var tempFormat = new TemporaryMagickFormat ( this , format ) ;
7157- Write ( file ) ;
7191+ Throw . IfNull ( file ) ;
7192+
7193+ Write ( file . FullName , format ) ;
7194+ file . Refresh ( ) ;
71587195 }
71597196
71607197 /// <summary>
@@ -7253,8 +7290,13 @@ public void Write(string fileName, MagickFormat format)
72537290 /// <param name="file">The file to write the image to.</param>
72547291 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
72557292 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
7256- public Task WriteAsync ( FileInfo file )
7257- => WriteAsync ( file , CancellationToken . None ) ;
7293+ public async Task WriteAsync ( FileInfo file )
7294+ {
7295+ Throw . IfNull ( file ) ;
7296+
7297+ await WriteAsync ( file . FullName ) ;
7298+ file . Refresh ( ) ;
7299+ }
72587300
72597301 /// <summary>
72607302 /// Writes the image to the specified file.
@@ -7263,13 +7305,12 @@ public Task WriteAsync(FileInfo file)
72637305 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
72647306 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
72657307 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
7266- public Task WriteAsync ( FileInfo file , CancellationToken cancellationToken )
7308+ public async Task WriteAsync ( FileInfo file , CancellationToken cancellationToken )
72677309 {
72687310 Throw . IfNull ( file ) ;
72697311
7270- var format = EnumHelper . ParseMagickFormatFromExtension ( file ) ;
7271- var bytes = format != MagickFormat . Unknown ? ToByteArray ( format ) : ToByteArray ( ) ;
7272- return FileHelper . WriteAllBytesAsync ( file . FullName , bytes , cancellationToken ) ;
7312+ await WriteAsync ( file . FullName , cancellationToken ) ;
7313+ file . Refresh ( ) ;
72737314 }
72747315
72757316 /// <summary>
@@ -7279,8 +7320,13 @@ public Task WriteAsync(FileInfo file, CancellationToken cancellationToken)
72797320 /// <param name="defines">The defines to set.</param>
72807321 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
72817322 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
7282- public Task WriteAsync ( FileInfo file , IWriteDefines defines )
7283- => WriteAsync ( file , defines , CancellationToken . None ) ;
7323+ public async Task WriteAsync ( FileInfo file , IWriteDefines defines )
7324+ {
7325+ Throw . IfNull ( file ) ;
7326+
7327+ await WriteAsync ( file , defines ) ;
7328+ file . Refresh ( ) ;
7329+ }
72847330
72857331 /// <summary>
72867332 /// Writes the image to the specified file.
@@ -7290,10 +7336,12 @@ public Task WriteAsync(FileInfo file, IWriteDefines defines)
72907336 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
72917337 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
72927338 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
7293- public Task WriteAsync ( FileInfo file , IWriteDefines defines , CancellationToken cancellationToken )
7339+ public async Task WriteAsync ( FileInfo file , IWriteDefines defines , CancellationToken cancellationToken )
72947340 {
7295- _settings . SetDefines ( defines ) ;
7296- return WriteAsync ( file , defines . Format , cancellationToken ) ;
7341+ Throw . IfNull ( file ) ;
7342+
7343+ await WriteAsync ( file . FullName , defines , cancellationToken ) ;
7344+ file . Refresh ( ) ;
72977345 }
72987346
72997347 /// <summary>
@@ -7303,8 +7351,13 @@ public Task WriteAsync(FileInfo file, IWriteDefines defines, CancellationToken c
73037351 /// <param name="format">The format to use.</param>
73047352 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
73057353 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
7306- public Task WriteAsync ( FileInfo file , MagickFormat format )
7307- => WriteAsync ( file , format , CancellationToken . None ) ;
7354+ public async Task WriteAsync ( FileInfo file , MagickFormat format )
7355+ {
7356+ Throw . IfNull ( file ) ;
7357+
7358+ await WriteAsync ( file , format ) ;
7359+ file . Refresh ( ) ;
7360+ }
73087361
73097362 /// <summary>
73107363 /// Writes the image to the specified file.
@@ -7314,12 +7367,12 @@ public Task WriteAsync(FileInfo file, MagickFormat format)
73147367 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
73157368 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
73167369 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
7317- public Task WriteAsync ( FileInfo file , MagickFormat format , CancellationToken cancellationToken )
7370+ public async Task WriteAsync ( FileInfo file , MagickFormat format , CancellationToken cancellationToken )
73187371 {
73197372 Throw . IfNull ( file ) ;
73207373
7321- var bytes = ToByteArray ( format ) ;
7322- return FileHelper . WriteAllBytesAsync ( file . FullName , bytes , cancellationToken ) ;
7374+ await WriteAsync ( file . FullName , format , cancellationToken ) ;
7375+ file . Refresh ( ) ;
73237376 }
73247377
73257378 /// <summary>
@@ -7414,7 +7467,9 @@ public Task WriteAsync(string fileName, CancellationToken cancellationToken)
74147467 {
74157468 var filePath = FileHelper . CheckForBaseDirectory ( fileName ) ;
74167469
7417- return WriteAsync ( new FileInfo ( filePath ) , cancellationToken ) ;
7470+ var format = EnumHelper . ParseMagickFormatFromExtension ( filePath ) ;
7471+ var bytes = format != MagickFormat . Unknown ? ToByteArray ( format ) : ToByteArray ( ) ;
7472+ return FileHelper . WriteAllBytesAsync ( filePath , bytes , cancellationToken ) ;
74187473 }
74197474
74207475 /// <summary>
0 commit comments