私のシナリオでは、バックグラウンドタスクでレンダリングする前に、変更していないBitmapCacheBrushをフリーズする必要があります。残念ながら、「このFreezableはフリーズできません」というエラーが表示されます。 フリーズ可能なオブジェクトでも、回避策やハッピーな方法でフリーズすることはできますか? この目標に達するには、リフレクションによって適切なプロパティを設定することは可能でしょうか?皆さん、事前にありがとうございます。フリーズすることができないオブジェクトをフリーズする方法
編集:(私のサンプルコードの要求に応じて)
public static class ext
{
public static async Task<BitmapSource> RenderAsync(this Visual visual)
{
var bounds = VisualTreeHelper.GetDescendantBounds(visual);
var bitmapCacheBrush = new BitmapCacheBrush(visual);
bitmapCacheBrush.BitmapCache = new BitmapCache();
// We need to disconnect the visual here to make the freezable freezable :). Of course this will make our rendering blank
//bitmapCacheBrush.Target = null;
bitmapCacheBrush.Freeze();
var bitmapSource = await Task.Run(() =>
{
var renderBitmap = new RenderTargetBitmap((int)bounds.Width,
(int)bounds.Height, 96, 96, PixelFormats.Pbgra32);
var dVisual = new DrawingVisual();
using (DrawingContext context = dVisual.RenderOpen())
{
context.DrawRectangle(bitmapCacheBrush,
null,
new Rect(new Point(), new Size(bounds.Width, bounds.Height)));
}
renderBitmap.Render(dVisual);
renderBitmap.Freeze();
return renderBitmap;
});
return bitmapSource;
}
}
これまでのところ私のお気に入りの質問タイトルだと思います。 –
私はC#と友人は何も知りませんが、タイトルはそんなに素晴らしい謎です!それはウッドチャックの事を打ち負かす。そしてその精神に沿って、答えは「あなたは冷凍できない凍結可能な物体を凍結することはできません! – SergeyA
Elsaに助けを求める:) – Guy