내 프로젝트 bin 폴더에 파일을 저장하려고합니다. 어떤 이유로 경로에 문자열을 지정하면비트 맵 저장시 GDI + 예외에 일반 오류가 발생했습니다.
string filePath = @"C:\Users\Craig\Documents\Visual Studio 2015\Projects\CreateTextExample\CreateTextExample\bin\ErrorLog";
Thread.Sleep(100);
bitmap.Save([email protected]"\ErrorImage.Bmp", ImageFormat.Bmp);
과 같은 문자가 저장됩니다. 나는 시도하고 저장할 때 그러나 나는 A generic error occurred in GDI+
확실하지 왜 이런 일이 말을 런타임 오류가
string filePath = System.IO.Directory.GetCurrentDirectory() + @"\ErrorLog";
Thread.Sleep(100);
bitmap.Save([email protected]"\ErrorImage.Bmp", ImageFormat.Bmp);
좋아한다. 처음에는 폴더 권한 일 수도 있지만 첫 번째 방법을 사용하면 작동하지 않는 것처럼 보입니다.
왜 그런가? 당신이 디렉토리가 존재하는지 확인해야 Bitmap
의 저장 방법을 사용하는 경우
string currentContent = String.Empty;
bitmap = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
string filePath = System.IO.Directory.GetCurrentDirectory() + @"\ErrorLog";
Thread.Sleep(100);
bitmap.Save([email protected]"\ErrorImage.Bmp", ImageFormat.Bmp);
왜 자고 있니? 또한 연결하려면 ['System.IO.Path.Combine'] (https://msdn.microsoft.com/en-us/library/system.io.path.combine (v = vs.110) .aspx)을 사용하십시오. 경로, 훨씬 청소기. – MrZander
예외 스택은 유용 할 수도 있습니다. – eschneider
"첫 번째 방법을 사용하여 작동합니다". 당신이 불가능을 제거했을 때, 남아있는 것이 무엇이든지간에, 진실이어야합니다. 'System.IO.Directory.GetCurrentDirectory()'는 반환한다고 생각하는 것을 반환합니까? 두 번째 접근 방식에서도'filePath'는'C : \ Users \ Craig \ Documents \ Visual Studio 2015 \ Projects \ CreateTextExample \ CreateTextExample \ bin \ ErrorLog'입니까? –