private bool disposedValue; // To detect redundant calls private void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { datStream?.Dispose(); datStreamDeflated?.Dispose(); outputStream.Dispose(); } disposedValue = true; } }
/// <summary> /// Finalizes the image creation and closes the file stream. </summary> /// <remarks> /// This MUST be called after writing the lines. /// </remarks> /// public void End() { if (rowNum != ImgInfo.Rows - 1) { throw new PngjOutputException("all rows have not been written"); } try { datStreamDeflated.Dispose(); datStream.Dispose(); WriteLastChunks(); WriteEndChunk(); if (this.ShouldCloseStream) { outputStream.Dispose(); } } catch (IOException e) { throw new PngjOutputException(e); } }