2012-09-10 57 views
0

林在我的Windows手機應用程序的輔助動態磁貼經歷與背景圖像的問題,它不伸展,適當地配合區塊(它是一個PNG圖片)的Windows Phone動態磁貼和backgroundImage源和拉伸問題

我得到的數據,然後創建我的瓦片數據:

var tileData = new StandardTileData 
     { 
      Title = titleString, 
      BackContent = contentString, 
      BackTitle = backTitleString, 
      BackgroundImage = new Uri(httpUrlString)     
     }; 

有沒有辦法改變拉伸或「retemplate」瓦?

此外,我找到了解決辦法here用WriteableBitmap的,但我不知道如何給這個位圖作爲源,因爲BackgroundImage屬性只接受一個URI

回答

2

您需要調整圖像給它好縱橫比(看便知here

那麼你就必須以保存生成的WriteableBitmap的在獨立存儲,就像這樣:

 // save image to isolated storage 
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      // use of "/Shared/ShellContent/" folder is mandatory! 
      using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/MyImage.jpg", System.IO.FileMode.Create, isf)) 
      { 
       wbmp.SaveJpeg(imageStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100); 
      } 
     } 

然後,您將能夠ŧ o創建瓷磚這樣的:

 StandardTileData NewTileData = new StandardTileData 
     { 
      Title = "Title", 
      // reference saved image via isostore URI 
      BackgroundImage = new Uri("isostore:/Shared/ShellContent/MyImage.jpg", UriKind.Absolute), 
     }; 
+0

謝謝您的回答!不幸的是,我仍然沒有解決我的問題,我嘗試調整這種方式,並創建writeablebitmap.then時,我得到例外,我試過這個BitmapImage bitmapImage = new BitmapImage(new Uri(img)); Image image = new Image(); image.Width = 173; image.Height = 173; image.Stretch = Stretch.UniformToFill; image.Source = bitmapImage; WriteableBitmap writeableBitmap = new WriteableBitmap(image,null);然後按照你的建議保存它,但是現在我的瓷磚上的圖像是黑色的 – user970012

+0

原始圖像的大小是多少?你會得到什麼例外? –

+0

圖像來自網絡來源,例如150 x 106像素也是PNG格式,我不知道這是否相關。例外情況是nullreferenceexception,writeablebitmap創建的無效指針 – user970012

1

的問題是圖像不滿載,因此無法正常渲染。我使用了ImageOpened事件,然後將其保存爲Olivier建議的