Esempio n. 1
0
        public static void sendImage(Piece img, Socket s, int compression)
        {
            MemoryStream ms = new MemoryStream();
            string contentType = "";

            if (compression == 0)
            {
                img.getImg(0).Save(ms, ImageFormat.Jpeg);
                contentType = "image/jpeg";
            }
            else
            {
                img.getImg(compression).Save(ms, ImageFormat.Png);
                contentType = "image/png";
            }

            string header = String.Format("HTTP/1.0 200 OK\nContent-Type: {0}\nAccept-Ranges: none\nCache-Control: max-age=3600\n\n", contentType);
            send(header, s, false);
            send(ms.ToArray(), s, true); // send image and close...
        }
Esempio n. 2
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
        }