當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageDraw.ImageDraw方法代碼示例

本文整理匯總了Python中PIL.ImageDraw.ImageDraw方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageDraw.ImageDraw方法的具體用法?Python ImageDraw.ImageDraw怎麽用?Python ImageDraw.ImageDraw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PIL.ImageDraw的用法示例。


在下文中一共展示了ImageDraw.ImageDraw方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_shape1

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_shape1(self):
        # Arrange
        im = Image.new("RGB", (100, 100), "white")
        draw = ImageDraw.Draw(im)
        x0, y0 = 5, 5
        x1, y1 = 5, 50
        x2, y2 = 95, 50
        x3, y3 = 95, 5

        # Act
        s = ImageDraw.Outline()
        s.move(x0, y0)
        s.curve(x1, y1, x2, y2, x3, y3)
        s.line(x0, y0)

        draw.shape(s, fill=1)

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_shape1.png")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:22,代碼來源:test_imagedraw.py

示例2: test_shape2

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_shape2(self):
        # Arrange
        im = Image.new("RGB", (100, 100), "white")
        draw = ImageDraw.Draw(im)
        x0, y0 = 95, 95
        x1, y1 = 95, 50
        x2, y2 = 5, 50
        x3, y3 = 5, 95

        # Act
        s = ImageDraw.Outline()
        s.move(x0, y0)
        s.curve(x1, y1, x2, y2, x3, y3)
        s.line(x0, y0)

        draw.shape(s, outline="blue")

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_shape2.png")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:22,代碼來源:test_imagedraw.py

示例3: test_floodfill_border

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_floodfill_border(self):
        # floodfill() is experimental

        # 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))

        # Act
        ImageDraw.floodfill(
            im, centre_point, ImageColor.getrgb("red"),
            border=ImageColor.getrgb("black"))

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_floodfill2.png")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:19,代碼來源:test_imagedraw.py

示例4: test_floodfill_thresh

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
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")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:19,代碼來源:test_imagedraw.py

示例5: _test_font

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def _test_font(self, font):
        im = Image.new('RGB', (255, 255), 'white')
        draw = ImageDraw.ImageDraw(im)
        self._test_leak(lambda: draw.text((0, 0), "some text "*1024,  # ~10k
                                          font=font, fill="black")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:7,代碼來源:test_font_leaks.py

示例6: test_sanity

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_sanity(self):
        im = hopper("RGB").copy()

        draw = ImageDraw.ImageDraw(im)
        draw = ImageDraw.Draw(im)

        draw.ellipse(list(range(4)))
        draw.line(list(range(10)))
        draw.polygon(list(range(100)))
        draw.rectangle(list(range(4))) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:12,代碼來源:test_imagedraw.py

示例7: test_valueerror

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_valueerror(self):
        im = Image.open("Tests/images/chi.gif")

        draw = ImageDraw.Draw(im)
        draw.line((0, 0), fill=(0, 0, 0)) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:7,代碼來源:test_imagedraw.py

示例8: test_mode_mismatch

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_mode_mismatch(self):
        im = hopper("RGB").copy()

        self.assertRaises(ValueError, ImageDraw.ImageDraw, im, mode="L") 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:6,代碼來源:test_imagedraw.py

示例9: helper_arc

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def helper_arc(self, bbox, start, end):
        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)

        # Act
        draw.arc(bbox, start, end)

        # Assert
        self.assert_image_similar(
            im, Image.open("Tests/images/imagedraw_arc.png"), 1) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imagedraw.py

示例10: test_arc_no_loops

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_arc_no_loops(self):
        # No need to go in loops
        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        start = 5
        end = 370

        # Act
        draw.arc(BBOX1, start=start, end=end)

        # Assert
        self.assert_image_similar(
            im, Image.open("Tests/images/imagedraw_arc_no_loops.png"), 1) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:16,代碼來源:test_imagedraw.py

示例11: test_arc_width

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_arc_width(self):
        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        expected = "Tests/images/imagedraw_arc_width.png"

        # Act
        draw.arc(BBOX1, 10, 260, width=5)

        # Assert
        self.assert_image_similar(im, Image.open(expected), 1) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imagedraw.py

示例12: test_arc_width_fill

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_arc_width_fill(self):
        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        expected = "Tests/images/imagedraw_arc_width_fill.png"

        # Act
        draw.arc(BBOX1, 10, 260, fill="yellow", width=5)

        # Assert
        self.assert_image_similar(im, Image.open(expected), 1) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imagedraw.py

示例13: test_bitmap

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_bitmap(self):
        # Arrange
        small = Image.open("Tests/images/pil123rgba.png").resize((50, 50))
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)

        # Act
        draw.bitmap((10, 10), small)

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_bitmap.png")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:14,代碼來源:test_imagedraw.py

示例14: helper_chord

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def helper_chord(self, mode, bbox, start, end):
        # Arrange
        im = Image.new(mode, (W, H))
        draw = ImageDraw.Draw(im)
        expected = "Tests/images/imagedraw_chord_{}.png".format(mode)

        # Act
        draw.chord(bbox, start, end, fill="red", outline="yellow")

        # Assert
        self.assert_image_similar(im, Image.open(expected), 1) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imagedraw.py

示例15: test_chord_width_fill

# 需要導入模塊: from PIL import ImageDraw [as 別名]
# 或者: from PIL.ImageDraw import ImageDraw [as 別名]
def test_chord_width_fill(self):
        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        expected = "Tests/images/imagedraw_chord_width_fill.png"

        # Act
        draw.chord(BBOX1, 10, 260, fill="red", outline="yellow", width=5)

        # Assert
        self.assert_image_similar(im, Image.open(expected), 1) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imagedraw.py


注:本文中的PIL.ImageDraw.ImageDraw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。