【问题标题】:creating standard tiles with background image from internet使用来自互联网的背景图像创建标准瓷砖
【发布时间】:2014-04-25 00:29:53
【问题描述】:

我想用来自直接网站的背景图片创建一个标准,

我在 wp8 中做的很好, 但相同的代码在 wp7 中不起作用

下面是代码:

void setTile(string title, string IconPath1x1, string IconPath2x2,
             string IconPath4x2, string IconPath2x2Back, string IconPath4x2Back,
             string wideContent, string targetUri)
{
    StandardTileData Standarddata = new StandardTileData()
    {
            //IconPath2x2 = "http://i.imgur.com/something.png"
            Title = title + "_",
            BackgroundImage = new Uri(IconPath2x2, UriKind.RelativeOrAbsolute),

            BackContent = "",
            BackTitle = title + "_",

            BackBackgroundImage = new Uri(IconPath1x1, UriKind.Absolute)
    };

    ShellTile tiletopin = ShellTile.ActiveTiles.FirstOrDefault(
                          x => x.NavigationUri.ToString().Contains(targetUri));

    if (tiletopin == null)
    {
        ShellTile.Create(
            new Uri(targetUri, UriKind.RelativeOrAbsolute), Standarddata);
    }
}

这个链接我试过了,还是不行

http://blog.safaribooksonline.com/2012/03/20/windows-phone-7-bringing-your-application-tile-to-life/

我错过了什么或者它在 wp7 中不起作用?

【问题讨论】:

    标签: c# silverlight windows-phone-7


    【解决方案1】:

    很遗憾,您需要下载图像并将其保存在本地。然后,您可以从隔离存储中引用图像

    string fileName = @"Shared\ShellContent\backgroundTileImage.jpg";
    if(TrySaveImage(fileName, "http://foo.com/bar.png"))
    {
        Uri uri = new Uri("isostore:/" + fileName, UriKind.Absolute);
        // Create the tile if we didn't find it already exists.
        var tileData = new StandardTileData
        {
            Title = "My Tile",
            BackgroundImage = uri,
        };
    }
    
    ...
    private bool TrySaveImage(string fileName, string url)
    {
        using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
        {
            try
            {
                var backImage = new Image();
                backImage.Height = backImage.Width = 173;
                backImage.Stretch = Stretch.None;
                backImage.Source = new BitmapImage(new Uri(url));
                backImage.Measure(new Size(173, 173));
                backImage.Arrange(new Rect(0, 0, 173, 173));
                var image = new WriteableBitmap(backImage, null);
    
                string directory = Path.GetDirectoryName(fileName);
                if (!store.DirectoryExists(directory))
                {
                    store.CreateDirectory(directory);
                }
                using (var stream = store.OpenFile(fileName, FileMode.OpenOrCreate))
                {
                    image.SaveJpeg(stream, 173, 173, 0, 100);
                }
            }
            catch
            {
                return false;
            }
        }
        return true;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 2023-03-11
      • 2017-08-18
      • 2016-03-10
      • 2014-02-08
      • 1970-01-01
      相关资源
      最近更新 更多