我有一個用戶控制一個網格:WriteableBitmap.Savejpeg不呈現網格文本(圖像是OK)
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneAccentBrush}">
<Image
x:Name="imgBack"
Opacity=".25" />
<Grid VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Some textblocks -->
</Grid>
圖像的柵格&源的大小是在運行時動態設置:
public void ChangeSizeAndImage(int width, int height, string backImagePath)
{
// Set the height and width
LayoutRoot.Width = width;
LayoutRoot.Height = height;
// Set the background image
imgBack.Source = new BitmapImage(new Uri(backImagePath, UriKind.RelativeOrAbsolute));
this.UpdateLayout();
}
我然後調用從UI元素&其保存到IsolatedStorage(後來加入了Windows Phone動態磁貼)
生成JPEG的方法我能夠成功地使用瓷磚上的圖像,除了我只看到具有黑色背景的圖像,並且我沒有看到任何文字。我認爲這與jpeg和透明PNG有關,但是,我使用一種顏色在上面的Grid上設置背景,所以我不確定爲什麼它會被認爲是透明的。
編輯1 我以編程方式初始化此用戶控件,設置一些屬性,並將它傳遞給創建圖像方法。我發現,如果我將這個用戶控件添加到一個頁面,然後使用調用創建圖像方法,它工作得很好。必須有一些關於它在頁面上呈現,導致一切正常排列。不幸的是,這種方法在我的情況下是不可能的。我能做些什麼來實現這個目標?控件上的UpdateLayout();
不起作用。