我正在使用Visual C#Express 10.我試圖從另一個.avi文件創建,打開並寫入.avi文件。我爲y項目使用了Aforge dlls。下面的代碼是通過點擊按鈕編程的。訪問路徑在C#Visual Express 2010中被拒絕
OpenFileDialog toy = new OpenFileDialog();
toy.Filter = "AVI files (*.avi)|*.avi|All files (*.*)|*.*";
toy.Title = "Open an AVI file";
toy.ShowDialog();
string wish = toy.FileName;
VideoFileReader reader = new VideoFileReader();
VideoFileWriter writer = new VideoFileWriter();
string fileName = @"C:\test.avi";
FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
我收到提示在上面一行
// open video file
reader.Open(wish);
for (int i = 0; i < 100; i++)
{
Bitmap videoFrame = reader.ReadVideoFrame();
int w = videoFrame.Width;
int h = videoFrame.Height;
writer.Open(@"C:\test.avi",w, h);
videoFrame.Save(i + ".bmp");
// dispose the frame when it is no longer required
//videoFrame.Dispose();
}
reader.Close();
我收到的錯誤是 「進入 'C:\ test.avi' 的路徑被拒絕」。 我已經在StackOverflow中嘗試了一些解決方案,其中包括更改C驅動器的權限和使用環境文件夾。請告訴我這個。編輯: 對不起,延遲。我也不能寫日誌文件。我試圖上傳圖片
編輯2: 這是一個例外。我從文本框中得到它,然後輸入它。我用xxxx取代了我的名字。
System.UnauthorizedAccessException: Access to the path 'C:\test.avi' is denied.
at System.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
Int32 rights, Boolean useRights, FileShare share, Int32 buffersize, FileOptions)
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy,
Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at VideoFramesTest.Form1.OpenAndSave() in
C:\Users\XXXX\documents\visual studio
2010\projects\VideoFramestest\VideoFramestest\Form1.cs:line42
好吧,看起來Aforge與此無關 - 只需創建「FileStream」,您的整個問題就可以在沒有任何對話或類似的情況下編寫。畢竟,你不會寫任何文件。這是什麼環境 - 它是一個本地客戶端應用程序,還是一個Web應用程序,或者是什麼?你能夠從命令行或在資源管理器中寫入驅動器的根目錄嗎? –
它是一個窗體。它是大型應用程序的第一步。我需要包含幾個功能,但我一開始就陷入困境。至於你的其他問題,我可以通過命令行寫入根文件夾。我不完全知道如何使用瀏覽器編寫。 – DetectiveFishLegs
這可能是各種不同的事情,將你的'writer.open'封裝在try catch中併發布異常。文件可能會打開,您可能需要管理員權限。我們不知道 – user1