Ejemplo n.º 1
0
        private void generateSnapshot()
        {
            Bitmap img;
            Bitmap scr = captureScreen();

            int screenWidth = scr.Width;
            int screenHeight = scr.Height;
            int index = 0;
            int currentPieceWidth = sliceWidth, currentPieceHeight = sliceHeight;

            for (int currentRow = 0; currentRow < screenHeight; currentRow += sliceHeight) // loop through Y
            {
                for (int currentColumn = 0; currentColumn < screenWidth; currentColumn += sliceWidth) // loop through X
                {
                    if ((currentColumn + currentPieceWidth) > screenWidth) // tiles smaller than slice width
                        currentPieceWidth = screenWidth - currentColumn;

                    if ((currentRow + currentPieceHeight) > screenHeight) // tiles smaller than slice height
                        currentPieceHeight = screenHeight - currentRow;

                    //number the current image
                    index++;
                    //copy the current slice to the image array
                    img = scr.Clone(new Rectangle(currentColumn, currentRow, currentPieceWidth, currentPieceHeight), scr.PixelFormat);

                    if ((pieces.Count - 1 >= index) && (pieces[index] != null)) // If the number of pieces is greater than the current piece, and the current piece is there...
                    {
                        if (CompareImages.Compare(img, ((Piece)pieces[index]).getImg(0)) != CompareImages.CompareResult.ciCompareOk) // compare them. If not matching... continue...
                        {
                            imagesToSend = imagesToSend + String.Format("\nimage{0:000}", index); // add this image to the list of updated images

                            Piece newPiece = new Piece(index, img); // create a new 'piece' object
                            pieces[index] = newPiece;               // replace the current piece in the array.
                            imagesToSend = imagesToSend + "/" + newPiece.getCheckSum();
                        }
                    }
                    else
                    {
                        Piece newPiece = new Piece(index, img); // it doesnt exist
                        pieces.Add(newPiece);                   // so add it.
                    }
                } // end X loop
                currentPieceWidth = sliceWidth; // reset the piece width back to slice width...
            } // end Y loop
        }