2012-09-10 56 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建议的