모두가 잘하고 있기를 바랍니다.
Screenshot.Net 라이브러리 를 사용하여 WPF 응용 프로그램에서 화면의 영역을 그린 스크린 샷을 가져옵니다. 내가 겪고있는 문제는 스크린 샷을 프로젝트 폴더 내의 디렉토리에 저장하는 것입니다.
이것은 라이브러리가 현재 이미지를 저장하는 방법이지만 어떤 디렉토리에도 저장되지 않습니다.
public static BitmapSource ToBitmapSource(this Bitmap bitmap)
{
using (var stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Png);
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(stream.ToArray());
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
}
디렉토리 저장 경로를 지정하려고 시도했지만 지금까지 작동하지 못했습니다. 진행 방법에 대한 조언을 주시면 감사하겠습니다.
먼저 byte[]
MemoryStream에서 가져옵니다.
stream.Position = 0;
byte[] imgBytes = stream.ToArray();
그런 다음 내장 라이브러리를 사용하여 작성하십시오.
string basePath="<Your path without File name>";
string fileName="<Your image name with extension>";
System.IO.File.WriteAllBytes(Path.Combine(basePath, fileName), imgBytes);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다