当前位置: 首页>>代码示例>>Python>>正文


Python Picture.getPixel方法代码示例

本文整理汇总了Python中Picture.getPixel方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.getPixel方法的具体用法?Python Picture.getPixel怎么用?Python Picture.getPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Picture的用法示例。


在下文中一共展示了Picture.getPixel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Test_Picture_GIF

# 需要导入模块: import Picture [as 别名]
# 或者: from Picture import getPixel [as 别名]
class Test_Picture_GIF(unittest.TestCase):

    # def setUp(self):
        # No code needed here
        # Would run at the start of every individual test

    # -------------------------------------------------------------
    #                       GIF TESTING
    # -------------------------------------------------------------

    def testPictureStrB1(self):
        '''Test Picture(String) constructor (gif) [1] - loading'''
        self.pict = Picture()
        # NOTE: USING 1 == true
        self.assertEqual(
            self.pict.load(WHITE_GIF), 1, 'white.gif could not be loaded')

    def testPictureStrB2(self):
        '''Test Picture(String) constructor (gif) [2] - filename'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(self.pict.getFileName(), WHITE_GIF, 'Filename %s != %s' % (
            self.pict.getFileName(), WHITE_GIF))

    def testPictureStrB3(self):
        '''Test Picture(String) constructor (gif) [3] - extension'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(self.pict.getExtension(), 'gif',
                         'File extension %s != gif' % self.pict.getExtension())

    def testPictureStrB4(self):
        '''Test Picture(String) constructor (gif) [4] - title'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(self.pict.getTitle(), WHITE_GIF_TITLE, 'Title %s != %s' % (
            self.pict.getTitle(), WHITE_GIF_TITLE))

    def testPictureStrB5(self):
        '''Test Picture(String) constructor (gif) [5] - width'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(
            self.pict.getWidth(), 50, 'Width %s != 50' % self.pict.getWidth())
        self.assertNotEqual(self.pict.getWidth(), 49, 'Width is 49?')

    def testPictureStrB6(self):
        '''Test Picture(String) constructor (gif) [6] - height'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(
            self.pict.getHeight(), 50, 'Height %s != 50' % self.pict.getHeight())

    def testPictureStrB7(self):
        '''Test Picture(String) constructor (gif) [7] - toString'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(self.pict.toString(), 'Picture, filename %s height 50 width 50' % WHITE_GIF,
                         'toString %s != Picture, filename %s height 50 width 50' % (self.pict.toString(), WHITE_GIF))

    def testPictureStrB8(self):
        '''Test Picture(String) constructor (gif) [8] - pixels'''
        self.pict = Picture(WHITE_GIF)
        self.height = self.pict.getHeight()
        self.width = self.pict.getWidth()
        if(self.height != 50):
            print('Warning: height not correct')
        if(self.width != 50):
            print('Warning: width not correct')
        for i in range(self.width):
            for j in range(self.height):
                self.pix = self.pict.getPixel(i, j)
                self.assertEqual(self.pix.getRed(), 255, 'Pixel (%s,%s): Red = %s != 255' % (
                    i, j, self.pix.getRed()))
                self.assertEqual(self.pix.getBlue(), 255, 'Pixel (%s,%s): Blue = %s != 255' % (
                    i, j, self.pix.getRed()))
                self.assertEqual(self.pix.getGreen(), 255, 'Pixel (%s,%s): Green = %s != 255' % (
                    i, j, self.pix.getRed()))
        self.pixarray = self.pict.getPixels()
        self.len = len(self.pixarray)
        self.assertEqual(
            self.len, 50 * 50, 'Pixel array size %s != %s' % (self.len, 50 * 50))
        for k in range(self.len):
            self.pix = self.pixarray[k]
            self.assertEqual(
                self.pix.getRed(), 255, 'Pixel (k:%s): Red = %s != 255' % (k, self.pix.getRed()))
            self.assertEqual(self.pix.getBlue(), 255, 'Pixel (k:%s): Blue = %s != 255' % (
                k, self.pix.getBlue()))
            self.assertEqual(self.pix.getGreen(), 255, 'Pixel (k:%s): Green = %s != 255' % (
                k, self.pix.getGreen()))

    def testPictureStrB(self):
        '''Test Picture(String) constructor (gif) [all]'''
        self.pict = Picture(WHITE_GIF)
        self.assertEqual(self.pict.getFileName(), WHITE_GIF, 'Filename %s != %s' % (
            self.pict.getFileName(), WHITE_GIF))
        self.assertEqual(self.pict.getExtension(), 'gif',
                         'File extension %s != gif' % self.pict.getExtension())
        self.assertEqual(self.pict.getTitle(), WHITE_GIF_TITLE, 'Title %s != %s' % (
            self.pict.getTitle(), WHITE_GIF_TITLE))
        self.height = self.pict.getHeight()
        self.assertEqual(self.height, 50, 'Height %s != 50' % self.height)
        self.width = self.pict.getWidth()
        self.assertEqual(self.width, 50, 'Width %s != 50' % self.width)
        self.assertNotEqual(self.width, 49, 'Width is 49?')
        self.assertEqual(self.pict.toString(), 'Picture, filename %s height 50 width 50' % WHITE_GIF,
#.........这里部分代码省略.........
开发者ID:HenryStevens,项目名称:jes,代码行数:103,代码来源:Test_Picture_GIF.py

示例2: Test_Picture_BMP

# 需要导入模块: import Picture [as 别名]
# 或者: from Picture import getPixel [as 别名]
class Test_Picture_BMP(unittest.TestCase):

    # def setUp(self):
    # No code needed here
    # Would run at the start of every individual test

    # -------------------------------------------------------------
    #                       BMP TESTING
    # -------------------------------------------------------------

    def testPictureStrB1(self):
        """Test Picture(String) constructor (bmp) [1] - loading"""
        self.pict = Picture()
        # NOTE: USING 1 == true
        self.assertEqual(self.pict.load("white.bmp"), 1, "white.bmp could not be loaded")

    def testPictureStrB2(self):
        """Test Picture(String) constructor (bmp) [2] - filename"""
        self.pict = Picture("white.bmp")
        self.assertEqual(self.pict.getFileName(), "white.bmp", "Filename %s != white.bmp" % self.pict.getFileName())

    def testPictureStrB3(self):
        """Test Picture(String) constructor (bmp) [3] - extension"""
        self.pict = Picture("white.bmp")
        self.assertEqual(self.pict.getExtension(), "bmp", "File extension %s != bmp" % self.pict.getExtension())

    def testPictureStrB4(self):
        """Test Picture(String) constructor (bmp) [4] - title"""
        self.pict = Picture("white.bmp")
        self.assertEqual(self.pict.getTitle(), "white.bmp", "Title %s != white.bmp" % self.pict.getTitle())

    def testPictureStrB5(self):
        """Test Picture(String) constructor (bmp) [5] - width"""
        self.pict = Picture("white.bmp")
        self.assertEqual(self.pict.getWidth(), 50, "Width %s != 50" % self.pict.getWidth())
        self.assertNotEqual(self.pict.getWidth(), 49, "Width is 49?")

    def testPictureStrB6(self):
        """Test Picture(String) constructor (bmp) [6] - height"""
        self.pict = Picture("white.bmp")
        self.assertEqual(self.pict.getHeight(), 50, "Height %s != 50" % self.pict.getHeight())

    def testPictureStrB7(self):
        """Test Picture(String) constructor (bmp) [7] - toString"""
        self.pict = Picture("white.bmp")
        self.assertEqual(
            self.pict.toString(),
            "Picture, filename white.bmp height 50 width 50",
            "toString %s != Picture, filename white.bmp height 50 width 50" % self.pict.toString(),
        )

    def testPictureStrB8(self):
        """Test Picture(String) constructor (bmp) [8] - pixels"""
        self.pict = Picture("white.bmp")
        self.height = self.pict.getHeight()
        self.width = self.pict.getWidth()
        if self.height != 50:
            print("Warning: height not correct")
        if self.width != 50:
            print("Warning: width not correct")
        for i in range(self.width):
            for j in range(self.height):
                self.pix = self.pict.getPixel(i, j)
                self.assertEqual(self.pix.getRed(), 255, "Pixel (%s,%s): Red = %s != 255" % (i, j, self.pix.getRed()))
                self.assertEqual(self.pix.getBlue(), 255, "Pixel (%s,%s): Blue = %s != 255" % (i, j, self.pix.getRed()))
                self.assertEqual(
                    self.pix.getGreen(), 255, "Pixel (%s,%s): Green = %s != 255" % (i, j, self.pix.getRed())
                )
        self.pixarray = self.pict.getPixels()
        self.len = len(self.pixarray)
        self.assertEqual(self.len, 50 * 50, "Pixel array size %s != %s" % (self.len, 50 * 50))
        for k in range(self.len):
            self.pix = self.pixarray[k]
            self.assertEqual(self.pix.getRed(), 255, "Pixel (k:%s): Red = %s != 255" % (k, self.pix.getRed()))
            self.assertEqual(self.pix.getBlue(), 255, "Pixel (k:%s): Blue = %s != 255" % (k, self.pix.getBlue()))
            self.assertEqual(self.pix.getGreen(), 255, "Pixel (k:%s): Green = %s != 255" % (k, self.pix.getGreen()))

    def testPictureStrB(self):
        """Test Picture(String) constructor (bmp) [all]"""
        self.pict = Picture("white.bmp")
        self.assertEqual(self.pict.getFileName(), "white.bmp", "Filename %s != white.bmp" % self.pict.getFileName())
        self.assertEqual(self.pict.getExtension(), "bmp", "File extension %s != bmp" % self.pict.getExtension())
        self.assertEqual(self.pict.getTitle(), "white.bmp", "Title %s != white.bmp" % self.pict.getTitle())
        self.height = self.pict.getHeight()
        self.assertEqual(self.height, 50, "Height %s != 50" % self.height)
        self.width = self.pict.getWidth()
        self.assertEqual(self.width, 50, "Width %s != 50" % self.width)
        self.assertNotEqual(self.width, 49, "Width is 49?")
        self.assertEqual(
            self.pict.toString(),
            "Picture, filename white.bmp height 50 width 50",
            "toString %s != Picture, filename white.bmp height 50 width 50" % self.pict.toString(),
        )
        for i in range(self.width):
            for j in range(self.height):
                self.pix = self.pict.getPixel(i, j)
                self.assertEqual(self.pix.getRed(), 255, "Pixel (%s,%s): Red = %s != 255" % (i, j, self.pix.getRed()))
                self.assertEqual(self.pix.getBlue(), 255, "Pixel (%s,%s): Blue = %s != 255" % (i, j, self.pix.getRed()))
                self.assertEqual(
                    self.pix.getGreen(), 255, "Pixel (%s,%s): Green = %s != 255" % (i, j, self.pix.getRed())
#.........这里部分代码省略.........
开发者ID:Alli1223,项目名称:Comp120-moodboard,代码行数:103,代码来源:Test_Picture_BMP.py


注:本文中的Picture.getPixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。