Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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());
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        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
                });
            }
        }