public static void GetTileAsJpegToStream(this DeepZoomGenerator dz, int level, int locationX, int locationY, Stream stream, int quality = 75) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var tileInfo = dz.GetTileInfo(level, locationX, locationY); using (var image = new Image <Bgra32>((int)tileInfo.Width, (int)tileInfo.Height)) { WriteImage(dz, image, tileInfo); byte[] buffer = ArrayPool <byte> .Shared.Rent(EnsureMinimumSize(tileInfo.TileWidth *tileInfo.TileHeight * 4 * 2)); try { using (var ms = new MemoryStream(buffer)) { image.SaveAsJpeg(ms, new JpegEncoder() { Quality = quality }); ms.SetLength(ms.Position); ms.Position = 0; ms.CopyTo(stream); } } finally { ArrayPool <byte> .Shared.Return(buffer); } } }
public static async Task GetTileAsPngToStreamAsync(this DeepZoomGenerator dz, int level, int locationX, int locationY, Stream stream) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var tileInfo = dz.GetTileInfo(level, locationX, locationY); using (var image = new Image <Bgra32>((int)tileInfo.Width, (int)tileInfo.Height)) { WriteImage(dz, image, tileInfo); byte[] buffer = ArrayPool <byte> .Shared.Rent(EnsureMinimumSize(tileInfo.TileWidth *tileInfo.TileHeight * 4 * 2)); try { using (var ms = new MemoryStream(buffer)) { image.SaveAsPng(ms); ms.SetLength(ms.Position); ms.Position = 0; await ms.CopyToAsync(stream).ConfigureAwait(false); } } finally { ArrayPool <byte> .Shared.Return(buffer); } } }
public static byte[] GetTileAsPng(this DeepZoomGenerator dz, int level, int locationX, int locationY, out TileInfo info) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var tileInfo = dz.GetTileInfo(level, locationX, locationY); info = tileInfo; using (var image = new Image <Bgra32>((int)tileInfo.Width, (int)tileInfo.Height)) { WriteImage(dz, image, tileInfo); byte[] buffer = ArrayPool <byte> .Shared.Rent(EnsureMinimumSize(tileInfo.TileWidth *tileInfo.TileHeight * 4 * 2)); try { using (var ms = new MemoryStream(buffer)) { image.SaveAsPng(ms); ms.SetLength(ms.Position); return(ms.ToArray()); } } finally { ArrayPool <byte> .Shared.Return(buffer); } } }
public static void GetTileAsPngToStream(this DeepZoomGenerator dz, int level, int locationX, int locationY, MemoryStream stream) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var info = dz.GetTileInfo(level, locationX, locationY); using var image = ReadImage(dz, info); image.SaveAsPng(stream); }
public static byte[] GetTileAsPng(this DeepZoomGenerator dz, int level, int locationX, int locationY, out TileInfo info) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } info = dz.GetTileInfo(level, locationX, locationY); using var image = ReadImage(dz, info); using var ms = PooledMemoryStreamManager.Shared.GetStream(); image.SaveAsPng(ms); return(ms.ToArray()); }
public static async Task GetTileAsPngToStreamAsync(this DeepZoomGenerator dz, int level, int locationX, int locationY, Stream stream, CancellationToken cancellationToken = default) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var info = dz.GetTileInfo(level, locationX, locationY); using var image = ReadImage(dz, info); using var ms = PooledMemoryStreamManager.Shared.GetStream(); image.SaveAsPng(ms); ms.Seek(0, SeekOrigin.Begin); await ms.CopyToAsync(stream, 4096, cancellationToken).ConfigureAwait(false); }
public static void GetTileAsPngToStream(this DeepZoomGenerator dz, int level, int locationX, int locationY, Stream stream) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var info = dz.GetTileInfo(level, locationX, locationY); using var image = ReadImage(dz, info); using var ms = PooledMemoryStreamManager.Shared.GetStream(); image.SaveAsPng(ms); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(stream); }
public static void GetTileAsPngToStream(this DeepZoomGenerator dz, int level, int locationX, int locationY, MemoryStream stream) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var tileInfo = dz.GetTileInfo(level, locationX, locationY); using (var image = new Image <Bgra32>((int)tileInfo.Width, (int)tileInfo.Height)) { WriteImage(dz, image, tileInfo); image.SaveAsPng(stream); } }
public static void GetTileAsJpegToStream(this DeepZoomGenerator dz, int level, int locationX, int locationY, MemoryStream stream, int quality = 75) { if (dz == null) { throw new ArgumentNullException(nameof(dz)); } var tileInfo = dz.GetTileInfo(level, locationX, locationY); using (var image = new Image <Rgba32>((int)tileInfo.Width, (int)tileInfo.Height)) { WriteImage(dz, image, tileInfo); image.SaveAsJpeg(stream, new JpegEncoder() { Quality = quality }); } }