public (Bitmap, string) CreateBarCode( string inputPath, FfmpegWrapper ffmpeg, CancellationToken cancellationToken, IProgress <double> progress = null) { Bitmap finalBitmap = null; Graphics finalBitmapGraphics = null; Graphics GetDrawingSurface(int width, int height) { if (finalBitmap == null) { finalBitmap = new Bitmap(width, height); finalBitmapGraphics = Graphics.FromImage(finalBitmap); } return(finalBitmapGraphics); } var barCount = (int)Math.Round((double)SettingsHandler.ImageWidth / SettingsHandler.BarWidth); var audioPath = Path.ChangeExtension(Path.GetFileName(inputPath), "wav"); audioPath = Path.Combine(SettingsHandler.OutputDir, audioPath.Replace(" ", "")); var source = ffmpeg.GetImagesFromMedia(inputPath, audioPath, barCount, cancellationToken); int?finalBitmapHeight = null; int x = 0; foreach (var image in source) { if (finalBitmapHeight == null) { finalBitmapHeight = SettingsHandler.ImageHeight ?? image.Height; } var surface = GetDrawingSurface(SettingsHandler.ImageWidth, finalBitmapHeight.Value); surface.DrawImage(image, x, 0, SettingsHandler.BarWidth, finalBitmapHeight.Value); x += SettingsHandler.BarWidth; progress?.Report((double)x / SettingsHandler.ImageWidth); image.Dispose(); } finalBitmapGraphics?.Dispose(); return(finalBitmap, audioPath); }
public Bitmap CreateBarCode( string inputPath, BarCodeParameters parameters, FfmpegWrapper ffmpeg, CancellationToken cancellationToken, IProgress <double> progress = null) { Bitmap finalBitmap = null; Graphics finalBitmapGraphics = null; Graphics GetDrawingSurface(int width, int height) { if (finalBitmap == null) { finalBitmap = new Bitmap(width, height); finalBitmapGraphics = Graphics.FromImage(finalBitmap); } return(finalBitmapGraphics); } var barCount = (int)Math.Round((double)parameters.Width / parameters.BarWidth); var source = ffmpeg.GetImagesFromMedia(inputPath, barCount, cancellationToken); int?finalBitmapHeight = null; int x = 0; foreach (var image in source) { if (finalBitmapHeight == null) { finalBitmapHeight = parameters.Height ?? image.Height; } var surface = GetDrawingSurface(parameters.Width, finalBitmapHeight.Value); surface.DrawImage(image, x, 0, parameters.BarWidth, finalBitmapHeight.Value); x += parameters.BarWidth; progress?.Report((double)x / parameters.Width); image.Dispose(); } finalBitmapGraphics?.Dispose(); return(finalBitmap); }