コード例 #1
0
        private void cameraTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                bmp.ImageOpened += ImageOpenedTrue;
                //imgPreview.Source = bmp;
                //bmp.DecodePixelHeight = 460;
                //Height="460" Margin="10,10,0,0" VerticalAlignment="Top" Width="684">
                WriteableBitmap wbmp = new WriteableBitmap(bmp);
                //txtImage.Text = "Korkeus: " + wbmp.PixelHeight + " Leveys: " + wbmp.PixelWidth;
                Bitmap image = (Bitmap)wbmp;
                //AForge.Imaging.Filters.Grayscale
                //Grayscale gs = new Grayscale(

                // create filter
                ResizeNearestNeighbor filter = new ResizeNearestNeighbor(700, 480);
                // apply the filter
                Bitmap resizeImage = filter.Apply(image);
                txtImage.Text = "Korkeus: " + resizeImage.Height + " Leveys: " + resizeImage.Width;
                // create grayscale filter (BT709)
                Grayscale GSfilter = new Grayscale(0.2125, 0.7154, 0.0721);
                // apply the filter
                Bitmap grayImage = GSfilter.Apply(resizeImage);

                // create filter
                Threshold BIfilter = new Threshold(70);
                // apply the filter
                BIfilter.ApplyInPlace(grayImage);

                // create filter
                Invert Invertfilter = new Invert();
                // apply the filter
                Invertfilter.ApplyInPlace(grayImage);

                AForge.Imaging.Filters.ConnectedComponentsLabeling Blobfilter = new AForge.Imaging.Filters.ConnectedComponentsLabeling();
                Bitmap newImage = Blobfilter.Apply(grayImage);
                BlobCounter blobCounter = new BlobCounter(newImage);
                blobCounter.FilterBlobs = true;
                blobCounter.MinWidth = 5;
                blobCounter.MinHeight = 5;
                Blob[] blobs = blobCounter.GetObjectsInformation();
                gos = new List<GameObject>();
                List<Blob> blobList = blobs.ToList();
                PointCollection extremePoints = new PointCollection();
                System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle();
                PointCollection edges;
                List<AForge.IntPoint> lst;
                List<int[]> intlist = new List<int[]>();
                GameObject go = new GameObject();
                foreach (Blob b in blobs)
                {
                    lst = blobCounter.GetBlobsEdgePoints(b);
                    edges = new PointCollection();
                    foreach (AForge.IntPoint p in lst)
                    {
                        edges.Add(new System.Windows.Point(p.X, p.Y));
                    }
                    /*
                    extremePoints.Add(new System.Windows.Point(b.Rectangle.X, b.Rectangle.Y));
                    extremePoints.Add(new System.Windows.Point(b.Rectangle.X+b.Rectangle.Width, b.Rectangle.Y));
                    extremePoints.Add(new System.Windows.Point(b.Rectangle.X, b.Rectangle.Y+b.Rectangle.Height));
                    extremePoints.Add(new System.Windows.Point(b.Rectangle.X + b.Rectangle.Width, b.Rectangle.Y + b.Rectangle.Height));
                     * */
                    gos.Add(new GameObject(b.Rectangle.Y,b.Rectangle.X,b.Rectangle.Width,b.Rectangle.Height,edges)); // x ja y käännettynä, jotta lopullisessa mallissa suunnat oikein.
                    //GameObject go = new GameObject(
                    //extremePoints.Clear();
                    //edges.Clear();
                }
                //Serialize("LevelName.bin", gos);
                //SaveToLocalFolderAsync(e.ChosenPhoto, "LevelNameBG.jpg");
                //writeJsonAsync();
                fileName = txtBoxLevelName.Text;
                jsonWrite(fileName);
                WriteableBitmap wb;
                wb = (WriteableBitmap)resizeImage;

                using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (iso.FileExists(fileName+"_bg.jpg"))
                    {
                        iso.DeleteFile(fileName+"_bg.jpg");
                    }
                    using (IsolatedStorageFileStream isostream = iso.CreateFile(fileName+"_bg.jpg"))
                    {
                        Extensions.SaveJpeg(wb, isostream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                        isostream.Close(); 
                    }
                }

                //Rectangle[] rects = blobCounter.GetObjectsRectangles();
                //txtImage.Text = txtImage.Text + "Number of rectangles:+ " + rects.Length;

                wbmp = (WriteableBitmap)newImage;

                imgImage.Source = wbmp;
                // BY PIXEL
                /*
                foreach (int pix in wbmp.Pixels)
                {
                    int a = pix >> 24;
                    int r = (pix & 0x00ff0000) >> 16;
                    int g = (pix & 0x0000ff00) >> 8;
                    int b = (pix & 0x000000ff);
                    Color c = new Color(r, g, b, a);
                    int intensity = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
                    if (intensity > 127) ; // BLACK / SOLID
                    else ; // WHITE / NON-SOLID
                }*/
                //byte[] baLevel = CustomConvertToBytes(bmp);
                /*
                WriteableBitmap wbmp = new WriteableBitmap(bmp as BitmapSource);
                imgPreview.Source = wbmp;*/
            }
        }
コード例 #2
0
        // UNOPTIMIZED!
        public bool CollisionPixel(GameObject go)
        {
            return true;
            foreach (Point p in this.edges)
            {

                foreach (Point po in go.edges)
                {
                    p.Equals(po);
                }
                //if (go.edges.Contains(p)) return true;
            }
            return false;
        }
コード例 #3
0
        private void loadLevel()
        {
            JsonRead();

            BitmapImage bmi = LoadImageFromIsolatedStorage();
            if (bmi != null)
            {
                //canvasWorld.Width = bmi.DecodePixelWidth;
                //canvasWorld.Height = bmi.DecodePixelHeight;
                ImageBrush brush = new ImageBrush();
                brush.ImageSource = bmi;
                canvasWorld.Background = brush;

            }

            Player = new Actor(0, 0, 10, 25, 1, 0, 100);
            PlayerTemp = new Actor(0, 0, 10, 25, 1, 0, 100);
            playerNoGravity = false;
            Canvas.SetLeft(Player.hitbox, 10);
            Canvas.SetTop(Player.hitbox, 10);
            canvasWorld.Children.Add(Player.hitbox);

            goal = new GameObject(400, 650, 30, 30);
            goal.Trigger = 1;

            //GObjs.Add(goal);
            System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
            rec.Width = goal.Width;
            rec.Height = goal.Height;
            rec.Fill = new SolidColorBrush(Colors.Red);
            Canvas.SetLeft(rec, goal.Left);
            Canvas.SetTop(rec, goal.Top);
            canvasWorld.Children.Add(rec);

            foreach (GameObject go in GObjs)
            {
                System.Windows.Shapes.Rectangle rec1 = new System.Windows.Shapes.Rectangle();
                rec.Width = 5;
                rec.Height = 5;
                rec.Fill = new SolidColorBrush(Colors.Red);
                Canvas.SetLeft(rec1, go.Left);
                Canvas.SetTop(rec1, go.Top);
                canvasWorld.Children.Add(rec1);

                System.Windows.Shapes.Rectangle rec2 = new System.Windows.Shapes.Rectangle();
                rec2.Width = 5;
                rec2.Height = 5;
                rec2.Fill = new SolidColorBrush(Colors.Blue);
                Canvas.SetLeft(rec2, go.Left + go.Width);
                Canvas.SetTop(rec2, go.Top + go.Height);
                canvasWorld.Children.Add(rec2);

                System.Windows.Shapes.Rectangle rec3 = new System.Windows.Shapes.Rectangle();
                rec3.Width = 5;
                rec3.Height = 5;
                rec3.Fill = new SolidColorBrush(Colors.Green);
                Canvas.SetLeft(rec3, go.Left);
                Canvas.SetTop(rec3, go.Top + go.Height);
                canvasWorld.Children.Add(rec3);
            }

            MessageBox.Show("Start Game");
            gameTime.Start();
        }
コード例 #4
0
        public bool Collision(GameObject go)
        {
            bool horizontalCollision = false;
            bool verticalCollision = false;
            if (go.Left < this.Left && this.Left < go.Left + go.Width)
            {
                horizontalCollision = true;
            }

            if (go.Left < this.Left + this.Width && this.Left + this.Width < go.Left + go.Width)
            {
                horizontalCollision = true;
            }

            if (go.Top < this.Top && this.Top < go.Top + go.Height)
            {
                verticalCollision = true;
            }
            if (go.Top < this.Top + this.Height && this.Top + this.Height < go.Top + go.Height)
            {
                verticalCollision = true;
            }

            if (horizontalCollision && verticalCollision)
            {
                return CollisionPixel(go);
            }

            if (!horizontalCollision)
            {
                if (this.Left < go.Left && go.Left < this.Left + this.Width) horizontalCollision = true;
            }
            if (!verticalCollision)
            {
                if (this.Top < go.Top && go.Top < this.Top + this.Height) verticalCollision = true;
            }
            if (horizontalCollision && verticalCollision)
            {
                return CollisionPixel(go);
            }
            if (!horizontalCollision && !verticalCollision)
            {
                if ((this.Left < go.Left && go.Left < this.Left + this.Width) && (this.Top < go.Top && go.Top < this.Top + this.Height)) // wholly inside
                {
                    return true;
                }
            }
            return false;
        }