1

編集:

これは私がしたことです:

ScreenCapture sc;
AviFile af;

Form1 コンストラクター:

sc = new ScreenCapture();
af = new AviFile();

Form1 timer1 tick イベントでは:

private void timer1_Tick(object sender, EventArgs e)
        {
            if (playImages == true)
            {
                timer1.Enabled = false;
                play();
                timer1.Enabled = true;
            }
            else
            {
                af.CreateAvi(this.sc);
            }
        }

変更後の AviFile クラス:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using AviFile;
using ScreenShotDemo;

namespace ScreenVideoRecorder
{
    class AviFile
    {
        AviManager aviManager;

        Bitmap bmp;

        public AviFile()
        {
            aviManager = new AviManager(@"d:\testdata\new.avi", false);
        }

        public void CreateAvi(ScreenCapture sc)
        {
            bmp = new Bitmap(sc.CaptureScreen());
            VideoStream aviStream = aviManager.AddVideoStream(false, 25, bmp);//dlg.Rate, bmp);
            aviStream.AddFrame(bmp);
            bmp.Dispose();
        }

        public AviManager avim
        {
            get
            {
                return aviManager;
            }
            set
            {
                aviManager = value;
            }
        }
    }
}

Form1ボタンクリックイベントで停止します:

private void button3_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            if (af != null)
            {
                af.avim.Close();
            }
        }

しかし、スクリーンショットを撮って数秒後に実行した後に停止する前に: これは、タイマーを開始してスクリーンショットを撮る button1 です:

private void button1_Click(object sender, EventArgs e)
        {
            playImages = false;
            timer1.Enabled = true;
        }

数秒後、例外が発生します。

Exception in AVIFileCreateStream: -2147205019


System.Exception was unhandled
  HResult=-2146233088
  Message=Exception in AVIFileCreateStream: -2147205019
  Source=AviFile
  StackTrace:
       at AviFile.VideoStream.CreateStreamWithoutFormat()
       at AviFile.VideoStream.CreateStream()
       at AviFile.VideoStream..ctor(Int32 aviFile, Boolean writeCompressed, Double frameRate, Bitmap firstFrame)
       at AviFile.AviManager.AddVideoStream(Boolean isCompressed, Double frameRate, Bitmap firstFrame)
       at ScreenVideoRecorder.AviFile.CreateAvi(ScreenCapture sc) in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorder\ScreenVideoRecorder\AviFile.cs:line 27
       at ScreenVideoRecorder.Form1.timer1_Tick(Object sender, EventArgs e) in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorder\ScreenVideoRecorder\Form1.cs:line 61
       at System.Windows.Forms.Timer.OnTick(EventArgs e)
       at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ScreenVideoRecorder.Program.Main() in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorder\ScreenVideoRecorder\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

例外はクラスにあります:私のクラスではない VideoStream ソースファイルをダウンロードしたサイトからのものです: http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile -としょうかん

どうすれば修正できますか?

4

1 に答える 1

1

あなたの質問からは、あなたが何を求めているのか完全には明らかではありません。

AviFileただし、スクリーンショットをディスクに保存してからロードするのではなく、スクリーンショットを直接 に入れたい場合があるようです。

コードの重要な部分は次のとおりです。

bitmap = (Bitmap)Bitmap.FromFile(Form1.imagesFiles[n]);
aviStream.AddFrame(bitmap);
bitmap.Dispose();

それらをファイルからメモリにロードする代わりに、次のことができます。

bitmap = new Bitmap(sc.CaptureScreen());
aviStream.AddFrame(bitmap);
bitmap.Dispose();

そうすれば、ディスクに保存するのではなく、AVI ストリームに直接挿入するだけです。

于 2013-04-08T21:34:03.573 に答える