1

Canvasコードで動的に生成された画像から画像を作成する Visual Studio 2013 でユニバーサル アプリを作成したいと考えています。キャンバスを UI に (Gridたとえば で) 表示すれば問題ありません。キャンバスを表示しないと、アプリがクラッシュして次のメッセージが表示されます。

値が想定範囲内にありません。

私が使用するコードがあります:

Canvas cn = new Canvas();
cn.Height = 100;
cn.Width = 100;
cn.Visibility = Visibility.Visible;
Button but = new Button();
Rectangle rect = new Rectangle();
rect.Width = 100;
rect.Height = 100;
rect.Margin = new Thickness(0);
SolidColorBrush bruch = new SolidColorBrush();
bruch.Color = Colors.Blue;
rect.Fill = bruch;
but.Width = 50;
but.Height = 50;
but.Content = "23";
but.Visibility = Visibility.Visible;
cn.Children.Add(rect);
cn.Children.Add(but);
but.Margin = new Thickness(25, 25, 0, 0);
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(cn, 100, 100);
outputImage.Source = renderTargetBitmap;

からこのコードを使用する予定なので、UI にキャンバスを表示したくありませんBackgroundTask

ここに私のサンプルプロジェクトがあります

4

1 に答える 1