public BMPImage copyPart(int x, int y, int width, int height) {
        BMPImage image = new BMPImage(this);
        image.imageHeader.biHeight = height;
        image.imageHeader.biWidth = width;
        image.fileHeader.bfSize = FILE_HEADER_SIZE + IMAGE_HEADER_SIZE + height * width;

        BMPColor[][] bitmap = new BMPColor[width + 2][height + 2];
        if(height > pixelData.bitmap.length) {
            height = pixelData.bitmap.length;
        }
        if(width > pixelData.bitmap[0].length) {
            width = pixelData.bitmap[0].length;
        }
        for(int j = 0; j <= height + 1; j++) {
            for(int i = 0; i <= width + 1; i++) {
                bitmap[j][i] = pixelData.bitmap[y + j][x + i];
            }
        }

        for(int i = 1; i <= width; i++) {
            bitmap[0][i] = new BMPColor(bitmap[1][i]);
            bitmap[height + 1][i] = new BMPColor(bitmap[height][i]);
        }
        for(int i = 1; i <= height; i++) {
            bitmap[i][0] = new BMPColor(bitmap[i][1]);
            bitmap[i][width+1] = new BMPColor(bitmap[i][width]);
        }

        bitmap[0][0] = new BMPColor();
        bitmap[height+1][0] = new BMPColor();
        bitmap[0][width+1] = new BMPColor();
        bitmap[height+1][width+1] = new BMPColor();

        bitmap[0][0].blue = (bitmap[1][0].blue + bitmap[0][1].blue)/2;
        bitmap[height+1][0].blue = (bitmap[height][0].blue + bitmap[height+1][1].blue)/2;
        bitmap[0][width+1].blue = (bitmap[0][width].blue + bitmap[1][width+1].blue)/2;
        bitmap[height+1][width+1].blue = (bitmap[height+1][width].blue + bitmap[height][width+1].blue)/2;

        bitmap[0][0].green = (bitmap[1][0].green + bitmap[0][1].green)/2;
        bitmap[height+1][0].green = (bitmap[height][0].green + bitmap[height+1][1].green)/2;
        bitmap[0][width+1].green = (bitmap[0][width].green + bitmap[1][width+1].green)/2;
        bitmap[height+1][width+1].green = (bitmap[height+1][width].green + bitmap[height][width+1].green)/2;

        bitmap[0][0].red = (bitmap[1][0].red + bitmap[0][1].red)/2;
        bitmap[height+1][0].red = (bitmap[height][0].red + bitmap[height+1][1].red)/2;
        bitmap[0][width+1].red = (bitmap[0][width].red + bitmap[1][width+1].red)/2;
        bitmap[height+1][width+1].red = (bitmap[height+1][width].red + bitmap[height][width+1].red)/2;

        image.pixelData.bitmap = bitmap;
        return image;
    }