示例#1
0
        private void ExportImages(IBackgroundTaskContext context, ref List <IPresentationImage> imagesToDispose)
        {
            ExportImageParams exportParams = new ExportImageParams();

            exportParams.Scale            = Scale;
            exportParams.ExportOption     = _exportOption;
            exportParams.DisplayRectangle = _clipboardItem.DisplayRectangle;
            exportParams.SizeMode         = SizeMode;
            exportParams.OutputSize       = new Size(Width, Height);
            exportParams.BackgroundColor  = BackgroundColor;

            using (Avi.VideoStreamWriter writer = new Avi.VideoStreamWriter(_selectedCodec))
            {
                if (!UseDefaultQuality)
                {
                    writer.Quality = _quality;
                }

                for (int i = 0; i < NumberOfImages; ++i)
                {
                    if (context != null && context.CancelRequested)
                    {
                        break;
                    }

                    if (context != null)
                    {
                        int    number  = i + 1;
                        string message = String.Format(SR.MessageFormatExportingFrame, number, NumberOfImages);
                        ReportProgress(context, message, number);
                    }

                    IPresentationImage image = ImageExporter.ClonePresentationImage(DisplaySet.PresentationImages[i]);
                    imagesToDispose.Add(image);

                    using (Bitmap bitmap = ImageExporter.DrawToBitmap(image, exportParams))
                    {
                        if (!writer.IsOpen)
                        {
                            //many codecs (like DivX) expect width and/or height to be divisible by 4.
                            int width  = NormalizeDimension(bitmap.Width);
                            int height = NormalizeDimension(bitmap.Height);

                            writer.Width     = width;
                            writer.Height    = height;
                            writer.FrameRate = this.FrameRate;

                            writer.Open(this.FilePath);
                        }

                        writer.AddBitmap(bitmap);
                    }
                }
            }
        }
示例#2
0
            private IPresentationImage GetImageForExport(IPresentationImage image)
            {
                if (IsAsynchronous)
                {
                    // A graphic should belong to (and be disposed on) a single thread
                    // and should not be rendered on multiple threads, so we clone it.
                    // Technically, we should be doing the clone on the main thread
                    // and then passing it to the worker, but that would require blocking
                    // the main thread while we cloned all the images.
                    _imagesToDispose.Add(image = ImageExporter.ClonePresentationImage(image));
                }

                return(image);
            }