Пример #1
0
            private static Point[] GetPoints(Random rand, double size, double margin, int numStars, Tuple<Vector[], int> vectorField)
            {
                //NOTE: Can't go all the way to the edge, stars would get cut off (the caller has to know the margin so it can properly overlap the images)
                double reducedSize = size - (margin * 2);

                Point[] points = Enumerable.Range(0, numStars).
                    Select(o => new Point(rand.NextDouble(reducedSize), rand.NextDouble(reducedSize))).
                    ToArray();

                if (vectorField != null)
                {
                    points = AdjustPoints(points, reducedSize, vectorField.Item1, vectorField.Item2);
                }

                Transform transform = new TranslateTransform(margin, margin);

                return points.
                    Select(o => transform.Transform(o)).
                    ToArray();
            }
        private void CropPhoto()
        {
            int x0 = (int)originalPhoto.Margin.Right;

            int xDisplacement = x0 - current;

            WriteableBitmap wb = new WriteableBitmap((int)cropArea.Width, (int)cropArea.Height);
            TranslateTransform t = new TranslateTransform();
            t.X = xDisplacement;
            Point p = new Point((int)cropArea.Width, (int)cropArea.Height);
            t.Transform(p);
            wb.Render(originalPhoto, t);
            wb.Invalidate();
            cropped.Source = wb;

            MainPage.isLandscape = true;
            NavigationService.Navigate(new Uri("/EditPicture.xaml", UriKind.Relative));
        }
Пример #3
0
       public void SaveToIsolatedStorage(Stream imageStream, string fileName)
        {
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists(fileName))
                {
                    myIsolatedStorage.DeleteFile(fileName);
                }

                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(fileName);
                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(imageStream);
                
                Image beforeCrop = new Image();
                Image afterCrop = new Image();

                if (bitmap.PixelWidth > bitmap.PixelHeight)
                {
                    afterCrop.Width = 800;
                    afterCrop.Height = 480;
                }
                else
                {
                    afterCrop.Width = 480;
                    afterCrop.Height = 800;
                }
                

                beforeCrop.Source = bitmap;

                WriteableBitmap wb = new WriteableBitmap((int)afterCrop.Width, (int)afterCrop.Height);

                Transform t = new TranslateTransform();
                Point p = new Point((int)afterCrop.Width, (int)afterCrop.Height);
                t.Transform(p);
                wb.Render(beforeCrop, t);
                wb.Invalidate();
                afterCrop.Source = wb;

                


                wb.SaveJpeg(fileStream, (int)afterCrop.Width, (int)afterCrop.Height, 0, 100);

               
              

                fileStream.Close();
            }
        }