示例#1
0
    def test_floodfill(self):
        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        draw.rectangle(BBOX2, outline="yellow", fill="green")
        centre_point = (int(W / 2), int(H / 2))
        red = ImageColor.getrgb("red")
        im_floodfill = Image.open("Tests/images/imagedraw_floodfill.png")

        # Act
        ImageDraw.floodfill(im, centre_point, red)

        # Assert
        self.assert_image_equal(im, im_floodfill)

        # Test that using the same colour does not change the image
        ImageDraw.floodfill(im, centre_point, red)
        self.assert_image_equal(im, im_floodfill)

        # Test that filling outside the image does not change the image
        ImageDraw.floodfill(im, (W, H), red)
        self.assert_image_equal(im, im_floodfill)

        # Test filling at the edge of an image
        im = Image.new("RGB", (1, 1))
        ImageDraw.floodfill(im, (0, 0), red)
        self.assert_image_equal(im, Image.new("RGB", (1, 1), red))
示例#2
0
    def test_floodfill_thresh(self):
        # floodfill() is experimental

        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        draw.rectangle(BBOX2, outline="darkgreen", fill="green")
        centre_point = (int(W / 2), int(H / 2))

        # Act
        ImageDraw.floodfill(im,
                            centre_point,
                            ImageColor.getrgb("red"),
                            thresh=30)

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_floodfill2.png"))