如何在辅助磁贴的Shared / ShellContent文件夹中保存png文件

时间:2014-04-17 18:30:11

标签: c# windows-phone-8 png transparent live-tile

我尝试过搜索这个但我最终只保存为不包含透明度的jpg。

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists("Shared/ShellContent/logo.jpg"))
                {
                    return;
                }

                IsolatedStorageFileStream fileStream1 = myIsolatedStorage.CreateFile("Shared/ShellContent/logo.jpg");

                Uri uri = new Uri("home.png", UriKind.Relative);
                StreamResourceInfo sri = null;
                sri = Application.GetResourceStream(uri);
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmapImage);

                Extensions.SaveJpeg(wb, fileStream1, wb.PixelWidth, wb.PixelHeight, 0, 95);    

                fileStream1.Close();
            }

如何保存图像,而不编码jpg格式?

1 个答案:

答案 0 :(得分:1)

我这样做了 http://toolstack.com/libraries/pngwriter

最终守则

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists("Shared/ShellContent/logo.png"))
                {
                    return;
                }

                IsolatedStorageFileStream fileStream1 = myIsolatedStorage.CreateFile("Shared/ShellContent/logo.png");

                Uri uri = new Uri("home.png", UriKind.Relative);
                StreamResourceInfo sri = null;
                sri = Application.GetResourceStream(uri);
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmapImage);

                wb.WritePNG( fileStream1 as System.IO.Stream);

                //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);

                fileStream1.Close();
            }