Example #1
0
        private void ShotInner([NotNull] string carId, [NotNull] string skinId, [CanBeNull] string destination,
                               [CanBeNull] ImageUtils.ImageInformation information, [CanBeNull] Action callback)
        {
            if (destination == null)
            {
                destination = Path.Combine(AcPaths.GetCarSkinDirectory(_acRoot, carId, skinId), _options.PreviewName);
            }

            var shotStream = new MemoryStream(_approximateSize ?? 100000);

            _renderer.Shot(_renderer.Width, _renderer.Height, _options.SoftwareDownsize ? 1d : 1d / _options.SsaaMultiplier, 1d, shotStream,
                           RendererShotFormat.Png);
            if (!_approximateSize.HasValue || _approximateSize < shotStream.Position)
            {
                _approximateSize = (int)(shotStream.Position * 1.2);
            }

            shotStream.Position = 0;
            ProcessConvertation(() => {
                using (var stream = File.Open(destination, FileMode.Create, FileAccess.ReadWrite)) {
                    ImageUtils.Convert(shotStream, stream,
                                       _options.SoftwareDownsize ? new Size(_options.PreviewWidth, _options.PreviewHeight) : (Size?)null, exif: information,
                                       format: destination.EndsWith(".png") ? ImageFormat.Png : ImageFormat.Jpeg);
                    callback?.Invoke();
                }
            }, DisposeCallback(shotStream));
        }