Exemplo n.º 1
0
        public void SavePhoto()
        {
            var writeableBitmap = new WriteableBitmap(picture);
            resizedOverlay = OverlayedPicture.Resize(writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
            writeableBitmap.ForEach(Fill);
              // Create a virtual store and file stream. Check for duplicate tempJPEG files.
            string tempJPEG = CreateFileName();
            var myStore = IsolatedStorageFile.GetUserStoreForApplication();
            if (myStore.FileExists(tempJPEG)){
                myStore.DeleteFile(tempJPEG);
            }
            IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
            writeableBitmap.SaveJpeg(myFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
            myFileStream.Close();

            // Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
            myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
            string fileName = CreateFileName();
            new MediaLibrary().SavePictureToCameraRoll(fileName, myFileStream);
        }
        public AdvGamePage()
        {
            InitializeComponent();

            var fileStream1 = Application.GetResourceStream(new Uri("TestImages/TestingUpper.png", UriKind.Relative));
            var s1 = new BitmapImage();
            using (var stream = fileStream1.Stream)
            {
                s1.SetSource(stream);
            }

            var upper = new WriteableBitmap(s1);

            var fileStream2 = Application.GetResourceStream(new Uri("TestImages/TestingLower.png", UriKind.Relative));
            var s2 = new BitmapImage();
            using (var stream = fileStream2.Stream)
            {
                s2.SetSource(stream);
            }

            var lower = new WriteableBitmap(s2);

            var upperEx = upper.GetBitmapContext();
            var lowerEx = lower.GetBitmapContext();

            UpperImage.Source = upper;
            LowerImage.Source = lower;

            upper.ForEach((x, y, color) =>
                {
                    var lowerColor = lower.GetPixel(x, y);
                    return new Color
                        {
                            R = (byte) (color.R - lowerColor.R),
                            G = (byte) (color.G - lowerColor.G),
                            B = (byte) (color.B - lowerColor.B),
                            A = color.A
                        };
                });
            upper.Invalidate();

            var changesPixels = new List<Point>();

            upper.ForEach((x, y, color) =>
                {
                    if (upper.GetPixel(x, y).R != 0)
                    {
                        lower.FillEllipseCentered(x, y, 10, 10, Colors.Red);
                        changesPixels.Add(new Point(x, y));
                    }

                    return color;
                });
            lower.Invalidate();

            //var indicator = new bool[480, 320];
            var startingPoint = changesPixels[0];
            var newPointToBeInvestigate = new List<Point> { startingPoint };
            changesPixels.Remove(startingPoint);
            //indicator[(int)startingPoint.X, (int)startingPoint.Y] = true;

            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            var i = 0;
            while (newPointToBeInvestigate.Count > 0 && i < newPointToBeInvestigate.Count)
            {
                var newPixels = changesPixels.Where(p => DistanceBetweenPoints(newPointToBeInvestigate[i], p)).ToList();

                foreach (var np in newPixels)
                {
                    changesPixels.Remove(np);
                    newPointToBeInvestigate.Add(np);
                }

                //foreach (var newP in newPixels.Where(newP => !indicator[(int)newP.X, (int)newP.Y]))
                //{
                //    indicator[(int)newP.X, (int)newP.Y] = true;
                //}

                i++;

            }
            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            foreach (var changeP in newPointToBeInvestigate)
            {
                lower.SetPixel((int)changeP.X, (int)changeP.Y, Colors.Green);
            }

            lower.Invalidate();
        }