如何设置和保存的背景图片中的Windows Phone? [英] How to set and save background image in windows phone?

查看:220
本文介绍了如何设置和保存的背景图片中的Windows Phone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个代码,因此用户可以设置自定义背景图片的应用程序:

I'm using this code, so user can sets custom background image for the application:

private void Button_Click(object sender, RoutedEventArgs e)
    {
        PhotoChooserTask photoChooserTask = new PhotoChooserTask();
        photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
        photoChooserTask.Show();
    }

    void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);

            var imageBrush = new ImageBrush
            {
                ImageSource = bmp,
                Opacity = 0.5d
            };
            App.RootFrame.Background = imageBrush;
        }
    }



但是这不会保存下一个应用程序背景图片午餐。
现在我怎么能保存选定的照片,以孤立的存储遗体的应用背景,即使重新启动应用程序后?

but this won't save background image for next application lunch. now how can I save chosen photo to isolated storage to remains as app background even after restarting the application?

推荐答案

保存图像不同步,仅适用于WP8。

Save image asynchronously, applies to WP8 only.

public static async Task SaveImageAsync(string imageFileName, BitmapImage image)
{
    // Get Students LocalFolder
    IStorageFolder folder = await ApplicationData.Current.LocalFolder
        .CreateFolderAsync("Images", CreationCollisionOption.OpenIfExists);


        IStorageFile file = await folder.CreateFileAsync(
            imageFileName, CreationCollisionOption.ReplaceExisting);

        using (Stream stream = await file.OpenStreamForWriteAsync())
        {                
            var wrBitmap = new WriteableBitmap(image);
            wrBitmap.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 100, 100);
        }
    }



读取图像同步两个WP7.x WP8:

Read image synchronously both WP7.x WP8:

public static BitmapImage LoadImage(string imageFileName)
{
    BitmapImage bitmapImage = null;

    using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication())
    {
         using (var isoStream = isoFile.OpenFile(
             imageFileName, FileMode.Open, FileAccess.Read))
         {
              bitmapImage = new BitmapImage();
              bitmapImage.SetSource(isoStream);
         }
    }

    return bitmapImage;
}

您可以在网上找到的大量资源,它只是谷歌。
http://msdn.microsoft。 COM / EN-US /库/ xf96a1wz(v = vs.110)的.aspx

You can find a bunch of resources online, just google it. http://msdn.microsoft.com/en-us/library/xf96a1wz(v=vs.110).aspx

这篇关于如何设置和保存的背景图片中的Windows Phone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆