Question

I have tried searching this but i only end up with saving as jpg which doesn't contains transparency.

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();
            }

How can i save image as it is, without encoding it jpg format?

Was it helpful?

Solution

I did it by following this http://toolstack.com/libraries/pngwriter

Final Code

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();
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top