ハードドライブに保存したファイルで四角形を塗りつぶしています。私は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を使用して開くことができると仮定しています。私はそれを試みるつもりです、そして、このスレッドを更新するために戻るでしょう。 –