【问题标题】:windows phone live tile backgroundimage source and stretch problemswindows phone live tile 背景图片来源和拉伸问题
【发布时间】:2012-09-10 21:43:05
【问题描述】:

我在我的 Windows Phone 应用程序的辅助动态磁贴上遇到了背景图像问题,它不能正确拉伸和适合磁贴(它是一个 .png 图像)

我获取数据,然后创建我的图块数据:

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

有什么方法可以改变拉伸或“重新设计”磁贴吗?

我还找到了带有可写位图的解决方案here,但我不明白如何将此位图作为源,因为 backgroundimage 属性只接受 Uri

【问题讨论】:

    标签: image windows-phone-7 live-tile


    【解决方案1】:

    您需要调整图像大小以使其具有良好的纵横比(请参阅答案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);
                }
            }
    

    然后您将能够像这样创建图块:

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

    【讨论】:

    • 感谢您的回答!不幸的是,我仍然没有解决我的问题,我尝试以这种方式调整大小,并且在创建 writeablebitmap 时出现异常。然后我尝试了这个 BitmapImage bitmapImage = new BitmapImage(new Uri(img));图像图像 = 新图像();图像.宽度 = 173;图像.高度 = 173; image.Stretch = Stretch.UniformToFill; image.Source = bitmapImage; WriteableBitmap writeableBitmap = new WriteableBitmap(image,null);然后按照你的建议保存,但现在我的图块上的图像是黑色的
    • 原图尺寸是多少?你得到什么例外?
    • 图片来自网络资源,例如 150 x 106 像素,它们也是 png 格式,我不知道这是否相关。异常是 nullreferenceexception,在 writeablebitmap 创建时指针无效
    • PNG 应该没问题。 BitmapImage 方法应该可以工作。你可以尝试调用 writeableBitmap.Invalidate() 来强制重绘位图吗?
    • 添加了 writeableBitmap.Invalidate();在保存之前,仍然是黑色的:/
    【解决方案2】:

    问题是图像未完全加载,因此未正确渲染。我使用了 ImageOpened 事件,然后按照 Olivier 的建议保存了它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多