Example #1
0
        private void saveImage(Stream image, bool shutdown = false)
        {
            using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
            {
                string filename = "mologo.bmp";
                if (shutdown)
                {
                    filename = "mologo_shutdown.bmp";
                }
            #if WP8
                using (var stream = File.Open(splashDir+filename,FileMode.Create))
            #else
                using (var stream = store.OpenFile(filename, System.IO.FileMode.Create))
            #endif
                {
                    var img = new Image();
                    img.Width = ResolutionSize.Width;
                    img.Height = ResolutionSize.Height;
                    var bi = new BitmapImage();
                    bi.SetSource(image);

                    img.Source = bi;
                    var img1 = img.ToImage();
                    IImageEncoder encoder = new BmpEncoder();
                    ExtendedImage ei = new ExtendedImage(img1);

                    if (ei.PixelHeight != (int)ResolutionSize.Height || ei.PixelWidth != (int)ResolutionSize.Width)
                    {
                        byte[] pixels = new byte[((int)ResolutionSize.Height) * ((int)ResolutionSize.Width)];
                        int i = 0;
                        foreach (byte b in pixels)
                        {
                            if (ei.Pixels.Length < i)
                            {
                                pixels[i] = b;
                            }
                            else
                            {
                                pixels[i] = 0;
                            }
                            i++;
                        }
                        ei.SetPixels((int)ResolutionSize.Width, (int)ResolutionSize.Height, ei.Pixels);
                    }
                    encoder.Encode(ei, stream);
                }
            }
        }
        private void invert_Click(object sender, EventArgs e)
        {
            ExtendedImage loadedImage;
            ExtendedImage filteredImage;
            Inverter filter;

            WriteableBitmap wb = new WriteableBitmap(image);
            loadedImage = new ExtendedImage();
            loadedImage.SetPixels(image.PixelWidth, image.PixelHeight, wb.ToByteArray());
            filter = new Inverter();
            filteredImage = new ExtendedImage(loadedImage);
            filter.Apply(filteredImage, loadedImage, new ImageTools.Rectangle(0, 0, loadedImage.PixelWidth, loadedImage.PixelHeight));
            var bitmap = filteredImage.ToBitmap();
            imageView.Source = bitmap;
        }