2014-01-13 61 views
1

我正在嘗試使用生成的圖像更新應用程序圖塊。我沒有得到任何錯誤,但圖像現在只是黑色,而不是這種顏色:'Color.FromArgb(255,0,100,50)'。任何想法爲什麼?生成的圖像顏色錯誤的瓷磚

//This have to be the Image, just a colored squer for the beginning 
var TestTile = new Grid() 
       { 
        Background   = new SolidColorBrush(Color.FromArgb(255, 0, 100, 50)), 
        HorizontalAlignment = HorizontalAlignment.Stretch, 
        VerticalAlignment = VerticalAlignment.Stretch, 
        Height    = 336, 
        Width    = 336, 
        Margin    = new Thickness(0, 12, 0, 0), 
       }; 

       //generation the image and save it within isoStorage 
       using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
       { 
        if (!store.DirectoryExists("shared/shellcontent")) 
        { 
         store.CreateDirectory("shared/shellcontent"); 
        } 
        var bitmap = new WriteableBitmap(336, 336); 
        bitmap.Render(TestTile, new TranslateTransform()); 
        var stream = store.CreateFile("/shared/shellcontent/test.jpg"); 
        bitmap.Invalidate(); 
        bitmap.SaveJpeg(stream, 366, 336, 0, 100); 
        stream.Close(); 
       } 

       // Tile Update 
       ShellTile PinnedTile = ShellTile.ActiveTiles.First(); 
       FlipTileData UpdatedTileData = new FlipTileData 
       { 

        BackgroundImage = new Uri("isostore:/shared/shellcontent/test.jpg", UriKind.RelativeOrAbsolute), 

       }; 
       PinnedTile.Update(UpdatedTileData); 

回答

1

如果有幫助,這是我如何保存平鋪圖像。

  1. 我總是使用Shared \ ShellContent \作爲位置。不知道情況的問題(它不應該)
  2. 我一直叫測量,然後將其發送到WriteableBitmap的
  3. 使用UriKind.Absolute爲背景URI

嘗試保存之前的UIElement安排你的形象像這樣:

string fileName = @"Shared\ShellContent\Tile.jpg"; 
Grid someElement = new Grid() 
{ 
    // Add Stuff 
} 
someElement.Measure(new Size(width, height)); 
someElement.Arrange(new Rect(0,0,width, height)); 
var bitmap = new WriteableBitmap(someElement, null); 

using(var stream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(fileName, FileMode.OpenOrCreate)) 
{ 
    bitmap.SaveJpeg(stream, width, height, 0, 100); 
} 

Uri uri = new Uri("isostore:/" + fileName, UriKind.Absolute); 
+0

好,我會嘗試使用矩形的顏色設置爲背景 – user3168511

0

嘗試使用「ms-appdata」URI方案訪問文件。然後將您的圖片的路徑將是如下:

BackgroundImage = new Uri("ms-appdata:///local/shared/shellcontent/test.jpg", UriKind.RelativeOrAbsolute) 

這就是我用它來設置磚塊圖像中我的應用程序之一,它按預期工作。

具體請參考「本地文件夾URI方案」的數據,Windows Phone的文章中瞭解更多信息:http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402541(v=vs.105).aspx#BKMK_Medialibrary

+0

對不起,我有這個問題已經 - 但現在我有其他的 - 我已經更新我的職務 – user3168511