带有自定义BitmapIcon的Windows Phone 8.1 AppBarButton

时间:2015-06-18 18:00:04

标签: windows-phone-8 windows-phone-8.1

我想为AppbarButton创建自定义图像。 我使用的是代码 Windows Phone 8.1 AppBarButton icon with 2 rows of text

RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(TodayTextBorder);

IBuffer pixels = await rtb.GetPixelsAsync();

string filename = "TodayIcon.png";
var outputFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);
using (var outputStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
    BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, outputStream);
    var dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
    enc.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)rtb.PixelWidth, (uint)rtb.PixelHeight, dpi, dpi, pixels.ToArray());
    await enc.FlushAsync();
}

BitmapIcon icon = new BitmapIcon();
icon.UriSource = new Uri("ms-appdata:///local/" + filename);
TodayAppbarButton.Icon = icon;

但它不起作用。好吧,它适用于模拟器和手机,以防应用程序直接从Visual Studio部署。但是,当我发布应用并从商店安装时,我会收到错误的appbar按钮图片(例如此http://i.imgur.com/de73cTo.png

0 个答案:

没有答案