コード例 #1
0
        public void Optimize(ISiGamePack pack)
        {
            var assets = pack.ImageAssets.ToArray();
            var n      = assets.Length;

            Log.Information($"ImageSizeReducer started. {n} assets to optimize");
            for (var i = 0; i < assets.Length; i++)
            {
                Log.Information($"ImageSizeReducer {i+1} / {n}: {assets[i].Name}");
                if (!_mimeWorker.IsImage(assets[i].Content))
                {
                    continue;
                }
                var originalSize = _imageProcessor.GetImageSize(assets[i].Content);
                var newSize      = CalculateNewSize(originalSize);
                var newAsset     = new Asset
                {
                    Name    = assets[i].Name,
                    Type    = assets[i].Type,
                    Content = _imageProcessor.EncodeImage(assets[i].Content, newSize, _settings.JpegQuality)
                };
                pack.InsertAsset(newAsset);
            }
        }