하드 드라이브에 저장 한 파일로 사각형을 채우려고합니다. ImageBrush를 사용해야한다는 것을 알고 있으며 이미지가 포함 된 리소스 일 경우 어떻게하는지 알 것입니다. 이 경우 파일이 만들어지고 하드 드라이브에 설정되지만 사각형 아래의 코드를 사용하려고하면 모양이 바뀝니다. 이미지가 아니라 예상했던대로 이미지가 다시 나타납니다. 보이지 않는).하드 드라이브의 파일을 사용하여 ImageBrush로 사각형을 채우는 방법
using (dynamic CommonDialog = AutomationFactory.CreateObject("WIA.CommonDialog"))
{
dynamic imageFile = CommonDialog.ShowAcquireImage();
if (imageFile != null)
{
string filePath = string.Format("d:\\{0}.jpg", Guid.NewGuid());
imageFile.SaveFile(filePath);
rectangle2.Fill = new ImageBrush()
{
ImageSource = new BitmapImage(new Uri(filePath, UriKind.Absolute))
};
}
}
업데이트 : 나는과 그 다음의 경우 내부의 코드 블록을 교체하여 작동이 얻을 수 있었다 다음 당신은에서, 이미지 또는 파일을 액세스 할 수 없습니다
{
string filePath = string.Format("d:\\{0}.jpg", Guid.NewGuid());
imageFile.SaveFile(filePath);
BitmapImage bitmapBase = new BitmapImage();
dynamic fileData = imageFile.FileData;
byte[] imageData = fileData.BinaryData;
MemoryStream ms = new MemoryStream(imageData);
bitmapBase.SetSource(ms);
WriteableBitmap writableBitmap = new WriteableBitmap(bitmapBase);
rectangle2.Fill = new ImageBrush() { ImageSource = (writableBitmap) };
}
죄송합니다. 나는 브라우저에서 일하고있다. 귀하의 응답에 따라 나는 그것을 저장하는 방식과 유사하게 CommonDialog를 사용할 수 있다고 가정하고 있습니다. 나는 그것을 시도 할 것이고이 스레드를 업데이트하기 위해 돌아갈 것이다. –