Example #1
0
        private static Bitmap MergeResult(Bitmap[,] results, int sx, int sy, int n)
        {
            var ix = results.GetLength(0);
            var iy = results.GetLength(1);

            int stx = 9999;
            int sty = 9999;

            for (int x = 0; x < ix; x++)
            {
                for (int y = 0; y < iy; y++)
                {
                    if (results[x, y] != null)
                    {
                        stx = Math.Min(x, stx);
                        sty = Math.Min(y, sty);
                    }
                }
            }

            var result = new Bitmap(n * sx, n * sy);

            using (var g = Graphics.FromImage(result))
            {
                for (int x = 0; x < n; x++)
                {
                    for (int y = 0; y < n; y++)
                    {
                        g.DrawImage(results[stx + x, sty + y], x * sx, y * sy);
                    }
                }
            }
            return(result);
        }
Example #2
0
 /// <summary>
 /// Creation des enclos
 /// </summary>
 private void PeuplerBitmapFence()
 {
     for (int i = 0; i < bmFence.GetLength(0); i++)
     {
         for (int j = 0; j < bmFence.GetLength(1); j++)
         {
             if (j == 6 && i == 10)
             {
                 bmFence[i, j] = TilesetImageGenerator.GetTile(43);
             }
             else if ((j == 0 && i != 13) || (j == 6 && i != 13))
             {
                 bmFence[i, j] = TilesetImageGenerator.GetTile(1);
             }
             else if ((i == 0 || i == 13) && (j != 0 || j != 6))
             {
                 bmFence[i, j] = TilesetImageGenerator.GetTile(2);
             }
             else
             {
                 bmFence[i, j] = TilesetImageGenerator.GetTile(0);
             }
         }
     }
 }
        /// <summary>
        /// Creates and resizes an image array of pacman sprites
        /// </summary>
        public void InitialiseImageArray()
        {
            int nPossibleDirections = Enum.GetNames(typeof(Direction)).Length;

            image = new Bitmap[nPossibleDirections, ANIMATION_FRAMES];

            //loads pacman images into image array
            for (int columns = 0; columns < nPossibleDirections; columns++)
            {
                string[] directionName = Enum.GetNames(typeof(Direction));
                image[columns, 0] = new Bitmap("PacManSprites/pacmanOrange.png");

                for (int rows = 1; rows < ANIMATION_FRAMES; rows++)
                {
                    string imageLocation = "PacManSprites/pacmanOrange" + directionName[columns] + rows + ".png";
                    image[columns, rows] = new Bitmap(imageLocation);
                }
            }

            //makes all the images in the ghost image array the same size.
            for (int columns = 0; columns < image.GetLength(0); columns++)
            {
                for (int rows = 0; rows < image.GetLength(1); rows++)
                {
                    Bitmap nicelySizedBitmap = new Bitmap(image[columns, rows], IMAGE_SIZE, IMAGE_SIZE);
                    image[columns, rows] = nicelySizedBitmap;

                    //makes the background of images transparent. Decides on the colour to make transparent based on top left pixel of image.
                    Color transparentColour = image[columns, rows].GetPixel(0, 0);
                    image[columns, rows].MakeTransparent(transparentColour);
                }
            }
        }
Example #4
0
        private void ButtonAutomaticAssemblyPuzzle_Click(object sender, EventArgs e)
        {
            // Array for puzzles with the lowest difference for each position
            Bitmap[,] bestChoisesForPuzzle = PuzzleSolver.GetBestPuzzleImage(listOfShuffledImages, numberOfRows, numberOfColumns);

            // List for swapping puzlles above and current in a game
            List <Bitmap> mysteryBoxesBitmaps = new List <Bitmap>(countOfFragments);

            for (int i = 0; i < bestChoisesForPuzzle.GetLength(0); i++)
            {
                for (int j = 0; j < bestChoisesForPuzzle.GetLength(1); j++)
                {
                    mysteryBoxesBitmaps.Add(bestChoisesForPuzzle[i, j]);
                }
            }

            for (int i = 0; i < countOfFragments; i++)
            {
                mysteryBoxes[i].Image      = mysteryBoxesBitmaps[i];
                mysteryBoxes[i].ImageIndex = i;
            }

            // Event for removing borders
            buttonCheck.PerformClick();

            buttonCheck.Enabled = false;
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //float gaussianStep = 1.6f;

            //float sigmaLimit = 1000;
            //GaussianKernel gk1 = new GaussianKernel(0);
            //Bitmap lastBit = null;

            //for (float i = 6.4f; i < sigmaLimit; i += gaussianStep)
            //{
            //    gk1.Sigma = i;
            //    Bitmap sigma1 = gk1.Conv((Bitmap)pictureBox1.Image);

            //    if (lastBit != null)
            //    {
            //        Bitmap dog = UnityTools.Diff(sigma1, lastBit);
            //        lastBit.Save(@"C:\MediaSlot\CloudDocs\Docs\课程\模式识别\Algorithms\TestImages\Records\gaussian-" + (i - gaussianStep).ToString("0.0") + ".bmp");
            //        sigma1.Save(@"C:\MediaSlot\CloudDocs\Docs\课程\模式识别\Algorithms\TestImages\Records\gaussian-" + i.ToString("0.0") + ".bmp");
            //        dog.Save(@"C:\MediaSlot\CloudDocs\Docs\课程\模式识别\Algorithms\TestImages\Records\" + i.ToString("0.0") + "-" + (i - gaussianStep).ToString("0.0") + ".bmp");
            //    }

            //    lastBit = Bitmap.FromHbitmap(sigma1.GetHbitmap());
            //}

            if (th1.ThreadState != ThreadState.Running)
            {
                th1 = new Thread(new ThreadStart(() =>
                {
                    SIFTSolver gk     = new SIFTSolver(1.6f);
                    gk.ColorFormat    = ColorFormat.GrayScale;
                    Bitmap[,] pyramid = gk.GetGaussianPyramid(UnityTools.ConvertToGray((Bitmap)pictureBox1.Image), 1, 3);
                    //Bitmap[,] pyramid = gk.GetGaussianPyramid((Bitmap)pictureBox1.Image, 3, 5);
                    Bitmap[,] dogs = gk.GetDoGs(pyramid);

                    for (int i = 0; i < pyramid.GetLength(0); i++)
                    {
                        for (int j = 0; j < pyramid.GetLength(1); j++)
                        {
                            pyramid[i, j].Save(@"C:\MediaSlot\CloudDocs\Docs\课程\模式识别\Algorithms\TestImages\Records\" + i + "-" + j + ".bmp");
                        }
                    }

                    for (int i = 0; i < dogs.GetLength(0); i++)
                    {
                        for (int j = 0; j < dogs.GetLength(1); j++)
                        {
                            dogs[i, j].Save(@"C:\MediaSlot\CloudDocs\Docs\课程\模式识别\Algorithms\TestImages\Records\dogs-" + i + "-" + j + ".bmp");
                        }
                    }
                }));

                th1.Start();
            }
        }
 public Bitmap[,] GetDoGs(Bitmap[,] gaussainPyramid)
 {
     Bitmap[,] dogs = new Bitmap[gaussainPyramid.GetLength(0), gaussainPyramid.GetLength(1) - 1];
     for (int i = 0; i < dogs.GetLength(0); i++)
     {
         for (int j = 0; j < dogs.GetLength(1); j++)
         {
             dogs[i, j] = UnityTools.Diff(gaussainPyramid[i, j], gaussainPyramid[i, j + 1]);
         }
     }
     return(dogs);
 }
Example #7
0
        /// <summary>
        /// Creation de la maison
        /// </summary>
        private void PeuplerBitmapHouse()
        {
            int countHouse = 5;

            for (int i = 0; i < bmHouse.GetLength(0); i++)
            {
                for (int j = 0; j < bmHouse.GetLength(1); j++)
                {
                    bmHouse[i, j] = TilesetImageGenerator.GetTile(countHouse);
                    countHouse++;
                }
            }
        }
Example #8
0
        /// <summary>
        /// Creation du puits
        /// </summary>
        private void PeuplerBitmapWell()
        {
            int countWell = 25;

            for (int i = 0; i < bmWell.GetLength(0); i++)
            {
                for (int j = 0; j < bmWell.GetLength(1); j++)
                {
                    bmWell[i, j] = TilesetImageGenerator.GetTile(countWell);
                    countWell++;
                }
            }
        }
Example #9
0
 private void DessinerAnimaux(Graphics gr)
 {
     for (int i = 0; i < bmAnimaux.GetLength(0); i++)
     {
         for (int j = 0; j < bmAnimaux.GetLength(1); j++)
         {
             if (bmAnimaux[i, j] != null)
             {
                 gr.DrawImage(bmAnimaux[i, j], i * 32, j * 32, 32, 32);
             }
         }
     }
 }
Example #10
0
        public Bitmap GetImage(uint i, Zoom zoom)
        {
            if (images == null)
            {
                return(null);
            }
            if (i > (uint)images.GetLength(0))
            {
                i = (uint)images.GetLength(0) - 1;
            }

            int numbZoom = (int)zoom;

            return(images[i, numbZoom / 2]);
        }
Example #11
0
        public void DisplayCommodityResults(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string[] rowIds, string screenshotName)
        {
            if (InvokeRequired)
            {
                Invoke(new DisplayCommodityResultsDelegate(DisplayCommodityResults), s, originalBitmaps, originalBitmapConfidences, rowIds, screenshotName);
                return;
            }

            if (_commodityTexts != null && _correctionColumn < _commodityTexts.GetLength(1)) // there is an existingClassification screenshot being processed...
            {
                _screenshotResultsBuffer.Add(new ScreeenshotResults {
                    originalBitmapConfidences = originalBitmapConfidences, originalBitmaps = originalBitmaps, s = s, rowIds = rowIds, screenshotName = screenshotName
                });
                ScreenshotsQueued("(" + (_screenshotResultsBuffer.Count + ocr.ScreenshotBuffer.Count + _preOcrBuffer.Count) + " queued)");
                return;
            }

            if (originalBitmaps.GetLength(0) != 0)
            {
                BeginCorrectingScreenshot(s, originalBitmaps, originalBitmapConfidences, rowIds, screenshotName);
            }
            else
            {
                tbCommoditiesOcrOutput.Text = "No rows found...";
            }
        }
Example #12
0
        public void invalidateRegion(int blockX, int blockY)
        {
            int x = blockX / regionWidthInBlocks;
            int y = blockY / regionHeightInBlocks;

            if (x < 0 || y < 0 || x >= cache.GetLength(0) || y >= cache.GetLength(1))
            {
                return;
            }

            if (cache[x, y] != null)
            {
                cache[x, y].Dispose();
            }
            cache[x, y] = null;            //Do bounds check
        }
Example #13
0
 void LoadGrid()
 {
     using (Graphics g = Graphics.FromImage(fullMap))
     {
         for (int x = 0; x < grid.GetLength(0); x++)
         {
             for (int y = 0; y < grid.GetLength(1); y++)
             {
                 //grid[x, y] = new Bitmap();
                 grid[x, y] = LoadImage(x + xDiff, y + yDiff);
                 g.DrawImage(grid[x, y], x * imageSize + 1, y * imageSize + 1);
             }
         }
     }
     pictureBox1.Image = fullMap;
 }
Example #14
0
        /// <summary>
        /// Constructeur du User Control Map et ce qui s'initialise au départ
        /// </summary>
        public Map()
        {
            InitializeComponent();
            //test
            hero = new Hero(46, 20, tabAjout, listeVisiteur, listeConcierge, listeAnimal);
            for (int x = 0; x < tabGazon.GetLength(0); x++)
            {
                for (int y = 0; y < tabGazon.GetLength(1); y++)
                {
                    tabGazon[x, y] = TilesetImageGenerator.GetTile(TilesetImageGenerator.GAZON);
                }
            }

            for (int x = 0; x < tabAjout.GetLength(0); x++)
            {
                for (int y = 0; y < tabAjout.GetLength(1); y++)
                {
                    tabAjout[x, y] = TilesetImageGenerator.GetTile(TilesetImageGenerator.GAZON);
                }
            }
            RemplacementGazonEnclos(0, 1);        //sable dans l'enclos
            AjoutTuileEnclos(0, 1, 14, 8);        //enclos en haut à gauche
            AjoutTuileEnclos(17, 1, 14, 8);       //enclos en haut au milieu
            AjoutTuileEnclos(34, 1, 14, 8);       //enclos en haut à droite
            AjoutTuileEnclosRhino(0, 11, 31, 10); //gros enclos en bas a gauche
            AjoutTuileBuisson(14, 1, 3, 8);       //buissons en haut a gauche
            AjoutTuileBuisson(31, 1, 3, 8);       //buissons en haut a droite
            AjoutTuileBuisson(31, 11, 3, 12);     //buissons en bas
            AjoutTuileBuisson(48, 1, 1, 22);      //buisson seul a droite
            AjoutTuileBuisson(0, 0, 49, 1);       //buisson en haut completement
            AjoutTuileRoute(0, 9, 49, 2);         //route horizontale
            AjoutTuileRoute(33, 11, 16, 12);      //route entrée
            AjoutTuileBuisson(47, 9, 2, 14);
            AjoutTuileDivers(43, 15, 4, 5, 18);   //MAISON
            AjoutTuileDivers(7, 8, 1, 1, 50);     //porte enclos en haut a gauche
            AjoutTuileDivers(24, 8, 1, 1, 50);    //porte enclos en haut au milieu
            AjoutTuileDivers(41, 8, 1, 1, 50);    //porte enclos en haut a droite
            AjoutTuileDivers(15, 11, 1, 1, 50);   //porte enclos en bas

            //Pour enlever les screen flash quand on se deplace, le CreateParams n'aide pas
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer,
                true);
        }
Example #15
0
        public Bitmap[,] traverse(Bitmap[,] inarr, int l1, int l2)
        {
            int d = -1;



            int i      = 0;
            int j      = 0;
            int i_prev = 0;
            int j_prev = 0;

            for (int k = 0; k <= inarr.GetLength(0); k++)
            {
                for (int l = 0; l < inarr.GetLength(1); l++)
                {
                    /*   i = i + 1;
                     * j = j + 1;
                     *
                     */

                    i += d;
                    j -= d;
                    if (i < 0)
                    {
                        i++;
                        d = -d;
                    }
                    else if (j < 0)
                    {
                        j++;
                        d = -d;
                    }
                    Console.WriteLine("i=" + (i));
                    Console.WriteLine("j=" + (j));
                    Console.WriteLine("i_prev=" + (i_prev));
                    Console.WriteLine("j_prev=" + (j_prev));
                    toexchange(inarr, i, j, i_prev, j_prev, l1, l2);
                    i_prev = i;
                    j_prev = j;
                }
            }


            return(inarr);
        }
Example #16
0
        static void DividePicture(Bitmap BitmapToDivide, Bitmap[,] BitmapsMatrix)
        {
            var         HeightOfMatrix = BitmapsMatrix.GetLength(0);
            var         WidthOfMatrix  = BitmapsMatrix.GetLength(1);
            var         Width          = BitmapToDivide.Width / WidthOfMatrix;
            var         Height         = BitmapToDivide.Height / HeightOfMatrix;
            PixelFormat Format         = BitmapToDivide.PixelFormat;

            for (int i = 0; i < HeightOfMatrix; i++)
            {
                var FixedHeight = i * Height;
                for (int j = 0; j < WidthOfMatrix; j++)
                {
                    Rectangle CloneRect = new Rectangle(j * Width, FixedHeight, Width, Height);
                    BitmapsMatrix[i, j] = BitmapToDivide.Clone(CloneRect, Format);
                }
            }
        }
Example #17
0
        //Place the track on the canvas
        public static Graphics PlaceTrack(Bitmap canvas)
        {
            int x = 0;
            int y = 0;

            Graphics g = Graphics.FromImage(canvas);

            for (int i = 0; i < CompleteTrack.GetLength(0); i++)
            {
                for (int j = 0; j < CompleteTrack.GetLength(1); j++)
                {
                    g.DrawImage(CompleteTrack[i, j], x, y, 256, 256);
                    x += 256;
                }
                x  = 0;
                y += 256;
            }
            return(g);
        }
Example #18
0
        public void traverse(Bitmap[,] inarr, int l1, int l2)
        {
            int k      = 0;
            int i      = 0;
            int k_prev = 0;
            int i_prev = 0;
            int m      = inarr.GetLength(0);
            int n      = inarr.GetLength(1);
            int l      = 0;

            while (k < m && l < n)
            {
                for (i = l; i < n; ++i)
                {
                    toexchange(inarr, k, i, k_prev, i_prev, l1, l2);
                    k_prev = k;
                    i_prev = i;
                }
                k++;
                for (i = k; i < m; ++i)
                {
                    toexchange(inarr, i, n - 1, k_prev, i_prev, l1, l2);
                }
                n--;
                if (k < m)
                {
                    for (i = n - 1; i >= 1; ++i)
                    {
                        toexchange(inarr, m - 1, i, k_prev, i_prev, l1, l2);
                    }
                    m--;
                }
                m--;
                if (l < n)
                {
                    for (i = m - 1; i >= k; --i)
                    {
                        toexchange(inarr, i, l, k_prev, i_prev, l1, l2);
                    }
                    l++;
                }
            }
        }
Example #19
0
 /// <summary>
 /// Construction de la rue et du gazon
 /// </summary>
 private void PeuplerBitmapMap()
 {
     for (int i = 0; i < bmMap.GetLength(0); i++)
     {
         for (int j = 0; j < bmMap.GetLength(1); j++)
         {
             if ((i == 2 && (j > 1 && j < 23)) || i == 19 || (i == 36 && (j > 1 && j < 23)) ||
                 (i == 40 && (j > 4 && j < 13)) || (j == 2 && (i > 1 && i < 37)) || (j == 12 && (i > 1 && i < 41)) ||
                 (j == 22 && (i > 1 && i < 37)) || (j == 23 && i == 18) || (j == 23 && i == 20) || (j == 24 && i == 18) ||
                 (j == 24 && i == 20) || (j == 0 && i == 18) || (j == 0 && i == 20) || (j == 1 && i == 18) || (j == 1 && i == 20))
             {
                 bmMap[i, j] = TilesetImageGenerator.GetTile(41);
             }
             else
             {
                 bmMap[i, j] = TilesetImageGenerator.GetTile(0);
             }
         }
     }
 }
Example #20
0
 // Removes all bitmaps from memory
 private void ClearAllBitmaps()
 {
     if (canvasChunks != null)
     {
         for (int i = 0; i < canvasChunks.GetLength(0); i++)
         {
             for (int j = 0; j < canvasChunks.GetLength(1); j++)
             {
                 if (canvasChunks[i, j] != null)
                 {
                     canvasChunks[i, j].Dispose();
                     canvasChunks[i, j] = null;
                 }
                 if (canvasChunksAlpha[i, j] != null)
                 {
                     canvasChunksAlpha[i, j].Dispose();
                     canvasChunksAlpha[i, j] = null;
                 }
             }
         }
     }
     if (canvasGraphics != null)
     {
         for (int i = 0; i < canvasGraphics.GetLength(0); i++)
         {
             for (int j = 0; j < canvasGraphics.GetLength(1); j++)
             {
                 if (canvasGraphics[i, j] != null)
                 {
                     canvasGraphics[i, j].Dispose();
                     canvasGraphics[i, j] = null;
                 }
                 if (canvasGraphicsAlpha[i, j] != null)
                 {
                     canvasGraphicsAlpha[i, j].Dispose();
                     canvasGraphicsAlpha[i, j] = null;
                 }
             }
         }
     }
 }
Example #21
0
 public void UpdateField(Bitmap[,] board)
 {
     chessBoard.Rows.Clear();
     for (int row = 0; row < board.GetLength(0); ++row)
     {
         var gridRow = new DataGridViewRow();
         for (int column = 0; column < board.GetLength(1); ++column)
         {
             var cell = new DataGridViewImageCell {
                 ValueType = typeof(Image)
             };
             var cellColor    = ((row + column) % 2 == 0) ? boardStyle.WhiteCellColor : boardStyle.BlackCellColor;
             var cellBitmap   = BitmapUtils.GetMonochromeBitmap(bitmapWidth, bitmapHeight, cellColor);
             var pieceBitmap  = board[row, column];
             var resultBitmap = BitmapUtils.GetOverlayedBitmap(cellBitmap, pieceBitmap);
             cell.Value = resultBitmap;
             gridRow.Cells.Add(cell);
         }
         chessBoard.Rows.Add(gridRow);
     }
 }
Example #22
0
        private void btnSolution_Click(object sender, EventArgs e)
        {
            Bitmap[,] bestChoise = GetBestPuzzleImage(shufImages);
            List <Bitmap> PB = new List <Bitmap>(numPieces);

            for (int i = 0; i < bestChoise.GetLength(0); i++)
            {
                for (int j = 0; j < bestChoise.GetLength(1); j++)
                {
                    PB.Add(bestChoise[i, j]);
                }
            }
            for (int n = 0; n < numPieces; n++)
            {
                picBoxes[n].Image      = PB[n];
                picBoxes[n].ImageIndex = n;
            }

            isPlaying = false;
            System.Windows.MessageBox.Show("Success will be on your side next time", "Try again!");
        }
Example #23
0
        private void InitializeGrid()
        {
            if (_Grid == null)
            {
                _Grid = new Bitmap[_GridWidth, _GridHeight];

                return;
            }

            Bitmap[,] newGrid = new Bitmap[_GridWidth, _GridHeight];

            for (int x = 0; x < _Grid.GetLength(0); x++)
            {
                for (int y = 0; y < _Grid.GetLength(1); y++)
                {
                    newGrid[x, y] = _Grid[x, y];
                }
            }

            _Grid = newGrid;
        }
Example #24
0
        private Bitmap CheckRndValue(Bitmap[,] imagesArray, Image image, int[] randArray)
        {
            Bitmap cloneImage = null;
            bool   flag       = false;

            for (int i = 0; i < imagesArray.GetLength(0); i++)
            {
                for (int j = 0; j < imagesArray.GetLength(1); j++)
                {
                    if (imagesArray[i, j] != image)
                    {
                        cloneImage = imagesArray[i, j];
                        //flag = false;
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }

            if (flag)
            {
                Random rnd = new Random();
                int    r1  = rnd.Next(0, imagesArray.GetLength(0));
                int    r2  = rnd.Next(0, imagesArray.GetLength(1));
                //randArray = { r1, r2}.To;
                //if (randArray.)
                //{

                //}
                CheckRndValue(imagesArray, imagesArray[r1, r2], randArray);
            }
            else
            {
                return(cloneImage);
            }

            return(null);
        }
Example #25
0
        private bool CheckImage(Bitmap[,] realImage, Bitmap[,] fishImage)
        {
            if (realImage.Length != fishImage.Length)
            {
                return(false);
            }

            for (int i = 0; i < realImage.GetLength(0); i++)
            {
                for (int j = 0; j < realImage.GetLength(1); j++)
                {
                    MessageBox.Show(realImage[i, j].Equals(fishImage[i, j]).ToString());
                    //  MessageBox.Show((Image)fishImage[i, j].ToString());
                    if ((Image)realImage[i, j] != (Image)fishImage[i, j])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        private Bitmap[,] GetScreenImages(Bitmap[,] targetBitmaps)
        {
            Rectangle screenRectangle;
            Rectangle captureRectangle;
            Point     location;
            Size      size;
            Bitmap    bitmap;

            screenRectangle = this.ScreenRectangle;

            size = new Size(screenRectangle.Width / targetBitmaps.GetLength(0), screenRectangle.Height / targetBitmaps.GetLength(1));

            bitmap = this.GetScreenImage();

            location         = new Point();
            captureRectangle = new Rectangle
            {
                Size = size
            };

            for (int x = 0; x < targetBitmaps.GetLength(0); x++)
            {
                for (int y = 0; y < targetBitmaps.GetLength(1); y++)
                {
                    location.X = (x * size.Width);
                    location.Y = (y * size.Height);

                    captureRectangle.Location = location;

                    using (Graphics graphics = Graphics.FromImage(targetBitmaps[x, y]))
                    {
                        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        graphics.DrawImage(bitmap, 0, 0, captureRectangle, GraphicsUnit.Pixel);
                    }
                }
            }

            return(targetBitmaps);
        }
Example #27
0
        /// <summary>
        /// Takes a 2-dimensional array of tiles and stitches it into a single Bitmap for display on the Map.
        /// </summary>
        /// <param name="tiles">2-dimensional array of tiles, [x by y]</param>
        /// <param name="opacity">Opacity of final image</param>
        /// <returns>Bitmap of the tiles stitched together</returns>
        public static Bitmap StitchTiles(Bitmap[,] tiles, short opacity)
        {
            var width  = tiles.GetLength(0) * 256;
            var height = tiles.GetLength(1) * 256;

            // create a bitmap to hold the combined image
            var finalImage = new Bitmap(width, height);

            // get a graphics object from the image so we can draw on it
            using (var g = Graphics.FromImage(finalImage))
            {
                // set background color
                g.Clear(Color.Transparent);

                using (var iaPic = new ImageAttributes())
                {
                    var cmxPic = new ColorMatrix
                    {
                        Matrix33 = opacity / 100f
                    };
                    iaPic.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    // go through each image and "draw" it on the final image
                    for (var y = 0; y < tiles.GetLength(1); y++)
                    {
                        for (var x = 0; x < tiles.GetLength(0); x++)
                        {
                            if (tiles[x, y] != null)
                            {
                                var tile = tiles[x, y];
                                g.DrawImage(tile, new Rectangle(x * 256, y * 256, tile.Width, tile.Height), 0, 0, tile.Width, tile.Height, GraphicsUnit.Pixel, iaPic);
                            }
                        }
                    }
                }
            }

            return(finalImage);
        }
Example #28
0
        private Bitmap[,] FisherYastes(Bitmap[,] bitmaps)
        {
            Random rnd = new Random();

            Bitmap[,] clone = bitmaps;
            for (int i = bitmaps.GetLength(0) - 1; i >= 1; i--)
            {
                for (int j = bitmaps.GetLength(1) - 1; j >= 1; j--)
                {
                    int r1 = rnd.Next(0, i + 1);
                    int r2 = rnd.Next(0, j + 1);

                    var temp = bitmaps[r1, r2];
                    bitmaps[r1, r2] = bitmaps[i, j];
                    bitmaps[i, j]   = temp;
                }
            }
            //if (clone == bitmaps)
            //    FisherYastes(bitmaps);

            return(bitmaps);
        }
Example #29
0
        /// <summary>
        /// Initialisation de mes boutons (choix) et du tableau de Bitmap qui contient les images du Mario Maker (ciel, plancher, etc.)
        /// </summary>
        private void Initialisation()
        {
            BtnNuage.BackgroundImage    = TilesetImageGenerator.GetTile(4);
            BtnBrique.BackgroundImage   = TilesetImageGenerator.GetTile(1);
            BtnPlancher.BackgroundImage = TilesetImageGenerator.GetTile(0);
            BtnCoin.BackgroundImage     = TilesetImageGenerator.GetTile(3);

            for (int i = 0; i < tab.GetLength(0); i++)
            {
                for (int j = 0; j < tab.GetLength(1); j++)
                {
                    if (j >= 14)
                    {
                        tab[i, j] = TilesetImageGenerator.GetTile(0);
                    }
                    else
                    {
                        tab[i, j] = TilesetImageGenerator.GetTile(2);
                    }
                }
            }
        }
Example #30
0
        public ActionResult <PuzzleResp> CreatePuzzle([FromBody] PuzzleReq request)//
        {
            //Image img = Image.FromFile(@"D:\My projects\Puzzle\PuzzleWF\Image\brain.jpg"); ;// берем картинку или Image.FromFile("D:\\123.png");
            try
            {
                PuzzleRepository rp = new PuzzleRepository(new PuzzleDBContext(), puzzle);
                int idImage         = rp.SaveImage(request.BImage, request.NameImage);      // save image

                System.Drawing.Image img = puzzle.ConvertFromBase64ToImage(request.BImage); // concert image
                Bitmap[,] bmp = puzzle.GetPuzzle(img, 100, 100);                            //cut imagepuzzle.GetPuzzle(img, request.WidthRect, request.HeightRect); //
                rp.SavePuzzle(idImage, bmp);

                Bitmap[,] rndBmp = puzzle.MixPuzzle(bmp); //mix images
                List <string> lstImage = new List <string>();

                for (int i = 0; i < rndBmp.GetLength(0); i++)
                {
                    for (int j = 0; j < rndBmp.GetLength(1); j++)
                    {
                        string imgPuz = puzzle.ConvertFromImageToBase64(rndBmp[i, j]);
                        lstImage.Add(imgPuz);
                    }
                }


                PuzzleResp resp = new PuzzleResp()
                {
                    Id = 1, ImageLst = lstImage, Name = request.NameImage
                };
                return(Ok(resp));
            }
            catch (Exception e)
            {
                return(this.StatusCode((int)HttpStatusCode.Conflict));
            }
        }
Example #31
0
        /// <summary>
        /// Creates and resizes an image array of pacman sprites
        /// </summary>
        public void InitialiseImageArray()
        {
            int nPossibleDirections = Enum.GetNames(typeof(Direction)).Length;
            image = new Bitmap[nPossibleDirections, ANIMATION_FRAMES];

            //loads pacman images into image array
            for (int columns = 0; columns < nPossibleDirections; columns++)
            {
                string[] directionName = Enum.GetNames(typeof(Direction));
                image[columns, 0] = new Bitmap("PacManSprites/pacmanOrange.png");

                for (int rows = 1; rows < ANIMATION_FRAMES; rows++)
                {
                    string imageLocation = "PacManSprites/pacmanOrange" + directionName[columns] + rows + ".png";
                    image[columns, rows] = new Bitmap(imageLocation);
                }
            }

            //makes all the images in the ghost image array the same size.
            for (int columns = 0; columns < image.GetLength(0); columns++)
            {
                for (int rows = 0; rows < image.GetLength(1); rows++)
                {
                    Bitmap nicelySizedBitmap = new Bitmap(image[columns, rows], IMAGE_SIZE, IMAGE_SIZE);
                    image[columns, rows] = nicelySizedBitmap;

                    //makes the background of images transparent. Decides on the colour to make transparent based on top left pixel of image.
                    Color transparentColour = image[columns, rows].GetPixel(0, 0);
                    image[columns, rows].MakeTransparent(transparentColour);
                }
            }
        }