コード例 #1
0
        static void Main(string[] args)
        {
            Compressor[] comp = EnumCompressors();
            foreach (Compressor c in comp)
            {
                Console.WriteLine(c.name);
            }

            Console.WriteLine("---");

            // create BitmapWriter component and configure it
            IBitmapWriter writer = (IBitmapWriter) new CVideoRecorder();

            writer.Init(100, 100, 5);

            // create DirectShow graph builder
            ICaptureGraphBuilder2 builder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2Cls();

            // create AVIMux and file writer component
            IBaseFilter     pMux;
            IFileSinkFilter unused;

            builder.SetOutputFileName(ref MEDIASUBTYPE_Avi, "test.avi", out pMux, out unused);

            IGraphBuilder graph;

            builder.GetFiltergraph(out graph);

            // add BitmapWriter as the source component
            graph.AddFilter((IBaseFilter)writer, "source");
            // if the compressor is specified, add it
            IBaseFilter compressor = null;

            if (args.Length != 0)
            {
                compressor = comp[int.Parse(args[0])].compressor;
                graph.AddFilter(compressor, "compressor");
            }

            // connect components
            builder.RenderStream(IntPtr.Zero, IntPtr.Zero, writer, compressor, pMux);

            // run the graph and send images
            IMediaControl control = (IMediaControl)graph;

            control.Run();
            for (int i = 0; i < 10; i++)
            {
                Bitmap bmp  = new Bitmap(@"..\..\test" + (i % 2) + ".bmp");
                IntPtr hBmp = bmp.GetHbitmap();
                writer.WriteBitmap((uint)hBmp.ToInt32());
                DeleteObject(hBmp);
                bmp.Dispose();
            }

            // stop the graph and flash any pending data throught the pipeline
            control.Stop();

            Console.WriteLine("done");
        }
コード例 #2
0
        /// <summary>
        /// Register the given bitmap writer so that it is available as a choice in the file save dialog.
        /// </summary>
        /// <param name="writer">A <see cref="IBitmapWriter"/> reference of the loader to be registered.</param>
        public static void RegisterBitmapWriter(IBitmapWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            bitmapWriterList.Add(writer);
        }
コード例 #3
0
ファイル: Recorder.cs プロジェクト: hayate891/freetrain
        /// <summary>
        /// Create a new recorder with the given setting.
        /// </summary>
        public Recorder(Rectangle rect, VCROptions config)
        {
            drawer = new QuarterViewDrawer(World.world, MainWindow.mainWindow.directDraw, rect);

            // register timer
            World.world.clock.registerRepeated(new ClockHandler(capture), TimeLength.fromMinutes(config.period));

            // create BitmapWriter component and configure it
            writer = (IBitmapWriter) new CVideoRecorder();
            writer.Init(rect.Width, rect.Height, config.fps);

            // create DirectShow graph builder
            ICaptureGraphBuilder2 builder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2Cls();

            // create AVIMux and file writer component
            IBaseFilter     pMux;
            IFileSinkFilter unused;

            builder.SetOutputFileName(ref MEDIASUBTYPE_Avi, "test.avi", out pMux, out unused);

            builder.GetFiltergraph(out graph);

            // add BitmapWriter as the source component
            graph.AddFilter((IBaseFilter)writer, "source");
            // if the compressor is specified, add it
            IBaseFilter compressor = config.compressor.bind();

            graph.AddFilter(compressor, "compressor");

            // connect components
            builder.RenderStream(IntPtr.Zero, IntPtr.Zero, writer, compressor, pMux);

            mediaControl = (IMediaControl)graph;

            // explicitly release local objects
//			Marshal.ReleaseComObject(builder);
//			Marshal.ReleaseComObject(pMux);
//			Marshal.ReleaseComObject(unused);
//			Marshal.ReleaseComObject(compressor);
        }
コード例 #4
0
 public ConsoleClient(ITagCloudBuilder tagCloudBuilder, IBitmapWriter bitmapWriter)
 {
     this.tagCloudBuilder = tagCloudBuilder;
     this.bitmapWriter = bitmapWriter;
 }
コード例 #5
0
        /// <summary>
        /// Load and convert the file specified by <paramref name="fileName"/> to the format specified by <paramref name="targetExt"/>
        /// and/or create a bitmap of the file. The bitmap format is defined by <paramref name="bitmapExt"/>. The result will be stored
        /// in the directory given by <paramref name="targetDir"/>.
        /// </summary>
        /// <param name="fileName">The full qualified filename of the file to process.</param>
        /// <param name="targetDir">The directory where the results should be stored.</param>
        /// <param name="targetExt">The target format to which to convert the given file. If empty, no conversion takes place.</param>
        /// <param name="bitmapExt">If not empty a bitmap of the type specified by this extension is created from the files (image) content.</param>
        /// <param name="bitmapDir">Specifies an additional directory where a copy of the bitmap (if any) should be created.</param>
        /// <returns>A <see cref="bool"/> value indicating the success of the operation.</returns>
        public bool BatchProcess(string fileName, string targetDir, string targetExt, string bitmapExt, string bitmapDir)
        {
            if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
            {
                return(false);
            }

            // load the file...
            try
            {
                // identify the loader on the basis of the extension...
                string          extension = Path.GetExtension(fileName);
                ISpecFileLoader loader    = AppContext.SpecFileLoaders.FindSupportingLoader(extension);
                if (loader == null)
                {
                    return(false);
                }

                // find the matching image writer
                IImagingWriter imageWriter = null;
                if (!string.IsNullOrEmpty(targetExt))
                {
                    foreach (var candidate in AppContext.ImagingWriters)
                    {
                        if (candidate != null)
                        {
                            bool found = false;
                            foreach (FileTypeDescriptor fileType in candidate.SupportedFileTypes)
                            {
                                if (fileType != null && fileType.IncludesExtension(targetExt))
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found)
                            {
                                imageWriter = candidate;
                                break;
                            }
                        }
                    }
                }

                // find the matching bitmap writer
                IBitmapWriter bitmapWriter = null;
                if (!string.IsNullOrEmpty(bitmapExt))
                {
                    foreach (IBitmapWriter candidate in AppContext.BitmapWriters)
                    {
                        if (candidate != null)
                        {
                            bool found = false;
                            foreach (FileTypeDescriptor fileType in candidate.SupportedFileTypes)
                            {
                                if (fileType != null && fileType.IncludesExtension(bitmapExt))
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found)
                            {
                                bitmapWriter = candidate as BitmapWriter;
                                break;
                            }
                        }
                    }
                }

                if (imageWriter == null && bitmapWriter == null)
                {
                    // no appropriate writers found for requested operation
                    return(false);
                }

                // let the loader load
                ISpecFileContent specFileContent = loader.Load(fileName);
                if (specFileContent == null)
                {
                    return(false);
                }

                BaseObjectList baseObjects = specFileContent.GetContent();
                if (baseObjects == null)
                {
                    return(false);
                }

                string outDir   = (!string.IsNullOrEmpty(targetDir) && Directory.Exists(targetDir)) ? targetDir : Path.GetDirectoryName(fileName);
                string filename = Path.GetFileNameWithoutExtension(fileName);

                // loop over the images an process
                foreach (BaseObject baseObject in baseObjects)
                {
                    var imaging = baseObject as Imaging;
                    if (imaging == null)
                    {
                        continue;
                    }

                    // perform image conversion if requested...
                    if (imageWriter != null)
                    {
                        // compose filename
                        string targetFile = filename + " - " + imaging.Name;
                        targetFile = Util.SubstitueInvalidPathChars(targetFile, '-');
                        targetFile = targetFile.Replace('.', '_');
                        targetFile = Path.Combine(outDir, targetFile + targetExt);
                        imageWriter.Write(imaging, targetFile, false);
                    }

                    // create a bitmap if required
                    if (bitmapWriter != null)
                    {
                        BitmapSourceList bitmaps = imaging.GetBitmaps();
                        if (bitmaps != null && bitmaps.Count > 0)
                        {
                            System.Windows.Media.Imaging.BitmapSource bitmap = bitmaps[0];
                            if (bitmap != null)
                            {
                                // compose filename
                                string bitmapFileName = filename + " - " + imaging.Name;
                                bitmapFileName = Util.SubstitueInvalidPathChars(bitmapFileName, '-');
                                bitmapFileName = bitmapFileName.Replace('.', '_');
                                string bitmapFilePath = Path.Combine(outDir, bitmapFileName + bitmapExt);
                                bitmapWriter.Write(bitmap, bitmapFilePath, false);
                                if (!string.IsNullOrEmpty(bitmapDir) && Directory.Exists(bitmapDir))
                                {
                                    bitmapFilePath = Path.Combine(bitmapDir, bitmapFileName + bitmapExt);
                                    bitmapWriter.Write(bitmap, bitmapFilePath, false);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Util.ReportException(e);
                return(false);
            }

            return(true);
        }
コード例 #6
0
 public ShadingRenderer(IBitmapWriter renderer)
 {
     this.renderer = renderer;
 }