コード例 #1
0
        public static async Task ProcessFrame(Config config, MemoryStream stream, int frame, int width, int height, string outPath)
        {
            MemoryStream?resizeMemStream = null;

            try
            {
                stream.Seek(0, SeekOrigin.Begin);
                var newWidth  = (int)Math.Floor(width / config.Model.ReadResolutionReduce);
                var newHeight = (int)Math.Floor(height / config.Model.ReadResolutionReduce);
                resizeMemStream        = new MemoryStream(newWidth * newHeight * 4);
                var(zones, zoneTotals) = SetupPixelZones(newWidth, newHeight, config.Model.ZoneRows, config.Model.ZoneColumns);
                BitmapProcessor.ReadBitmap(stream, width, height, newWidth, newHeight, config.Model.ReadResolutionReduce, config.Model.ZoneRows, config.Model.ZoneColumns, zones, zoneTotals, 4, resizeMemStream);

                zoneTotals.CalculateAverages();

                newWidth  = (int)Math.Floor(config.Model.ZoneColumns * config.Model.ResizeScale);
                newHeight = (int)Math.Floor(config.Model.ZoneRows * config.Model.ResizeScale);

                var image     = new MemoryStream(config.Model.ZoneColumns * config.Model.ZoneRows * 3);
                var blurImage = new MemoryStream(newWidth * newHeight * 3);

                (image, blurImage) = BitmapProcessor.PreparePostBitmap(zones, config.Model.ZoneColumns, config.Model.ZoneRows, newWidth, newHeight, config.Model.ResizeFilter, config.Model.ResizeSigma, image, blurImage);
                await ImageHandler.WriteImageToFile(blurImage, newWidth, newHeight, Path.Combine(outPath, $"out{frame.ToString().PadLeft(6, '0')}.png"), pixelFormat : PixelFormat.Rgb24);

                await blurImage.DisposeAsync();

                await image.DisposeAsync();

                foreach (var zone in zones)
                {
                    zone.Dispose();
                }
                zoneTotals.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                if (resizeMemStream != null)
                {
                    await resizeMemStream.DisposeAsync();
                }
                await stream.DisposeAsync();
            }
        }