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


Python Picture.explore方法代碼示例

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


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

示例1: Test_Picture_BOOK

# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import explore [as 別名]
class Test_Picture_BOOK(unittest.TestCase):

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

    def testDistance(self):
        '''Test Book - Color distances'''
        self.color1 = Color(81, 63, 51)
        self.color2 = Color(255, 51, 51)
        self.distance = Pixel.colorDistance(self.color1, self.color2)
        self.assertEqual(self.distance, 174.41330224498358, 'Distances: %s != %s' % (
            self.distance, 174.41330224498358))

    def testShow(self):
        '''Test Showing - YOU SHOULD NOW SEE A PICTURE WINDOW WITH BARBARA.JPG'''
        self.pict = Picture(PICTURES + "barbara.jpg")
        self.pict.show()
        success = swing.JOptionPane.showConfirmDialog(
            None, 'Does a window show barbara.jpg?', 'TestShowPicOP', swing.JOptionPane.YES_NO_OPTION)
        self.assertEqual(
            success, swing.JOptionPane.YES_OPTION, 'Failed to show barbara.jpg in window.')

    def testExplore(self):
        '''Test Browsing - YOU SHOULD NOW SEE A PICTURE EXPLORER WINDOW WITH BARBARA.JPG'''
        self.pict = Picture(PICTURES + "barbara.jpg")
        self.pict.explore()
        success = swing.JOptionPane.showConfirmDialog(
            None, 'Does the explorer start with barbara.jpg?', 'TestExplorerOP', swing.JOptionPane.YES_NO_OPTION)
        self.assertEqual(success, swing.JOptionPane.YES_OPTION,
                         'Failed to show barbara.jpg in explorer.')

    def testDecreaseRed(self):
        '''Test BOOK - Decrease red (by 50%)'''
        JESConfig.getInstance().setSessionWrapAround(0)
        self.pict = Picture(PICTURES + "barbara.jpg")
        for p in self.pict.getPixels():
            value = p.getRed()
            p.setRed(int(value * 0.5))
        self.pict.write(OUTPUT + "testdecred.jpg")
        self.picttest1 = Picture(OUTPUT + "testdecred.jpg")
        self.picttest2 = Picture(PICTURES + "barb-decred.jpg")
        self.assertEqual(self.picttest1.getWidth(), self.picttest2.getWidth(
        ), 'Widths are not the same (%s != %s)' % (self.picttest1.getWidth(), self.picttest2.getWidth()))
        self.assertEqual(self.picttest1.getHeight(), self.picttest2.getHeight(
        ), 'Heights are not the same (%s != %s)' % (self.picttest1.getHeight(), self.picttest2.getHeight()))
        for i in range(self.picttest1.getWidth()):
            for j in range(self.picttest1.getHeight()):
                self.assertEqual(self.picttest1.getBasicPixel(i, j), self.picttest2.getBasicPixel(
                    i, j), 'Pixels (%s, %s) do not match (%s != %s) - see output file testdecred.jpg' % (i, j, self.picttest1.getBasicPixel(i, j), self.picttest2.getBasicPixel(i, j)))

    def testIncreaseRed(self):
        '''Test BOOK - Increase red (by 20%)'''
        JESConfig.getInstance().setSessionWrapAround(0)
        self.pict = Picture(PICTURES + "barbara.jpg")
        for p in self.pict.getPixels():
            value = p.getRed()
            p.setRed(int(value * 1.2))
        self.pict.write(OUTPUT + "testincred.jpg")
        self.picttest1 = Picture(OUTPUT + "testincred.jpg")
        self.picttest2 = Picture(PICTURES + "barb-incred.jpg")
        self.assertEqual(self.picttest1.getWidth(), self.picttest2.getWidth(
        ), 'Widths are not the same (%s != %s)' % (self.picttest1.getWidth(), self.picttest2.getWidth()))
        self.assertEqual(self.picttest1.getHeight(), self.picttest2.getHeight(
        ), 'Heights are not the same (%s != %s)' % (self.picttest1.getHeight(), self.picttest2.getHeight()))
        for i in range(self.picttest1.getWidth()):
            for j in range(self.picttest1.getHeight()):
                self.assertEqual(self.picttest1.getBasicPixel(i, j), self.picttest2.getBasicPixel(
                    i, j), 'Pixels (%s, %s) do not match (%s != %s) - see output file testincred.jpg' % (i, j, self.picttest1.getBasicPixel(i, j), self.picttest2.getBasicPixel(i, j)))

    def testClearBlue(self):
        '''Test BOOK - Clear blue'''
        self.pict = Picture(PICTURES + "barbara.jpg")
        for p in self.pict.getPixels():
            p.setBlue(0)
        self.pict.write(OUTPUT + "testclrblue.jpg")
        self.picttest1 = Picture(OUTPUT + "testclrblue.jpg")
        self.picttest2 = Picture(PICTURES + "barb-clrblue.jpg")
        self.assertEqual(self.picttest1.getWidth(), self.picttest2.getWidth(
        ), 'Widths are not the same (%s != %s)' % (self.picttest1.getWidth(), self.picttest2.getWidth()))
        self.assertEqual(self.picttest1.getHeight(), self.picttest2.getHeight(
        ), 'Heights are not the same (%s != %s)' % (self.picttest1.getHeight(), self.picttest2.getHeight()))
        for i in range(self.picttest1.getWidth()):
            for j in range(self.picttest1.getHeight()):
                self.assertEqual(self.picttest1.getBasicPixel(i, j), self.picttest2.getBasicPixel(
                    i, j), 'Pixels (%s, %s) do not match (%s != %s) - see output file testclrblue.jpg' % (i, j, self.picttest1.getBasicPixel(i, j), self.picttest2.getBasicPixel(i, j)))

    def testLighten(self):
        '''Test BOOK - Lighten'''
        JESConfig.getInstance().setSessionWrapAround(0)
        self.pict = Picture(PICTURES + "barbara.jpg")
        for p in self.pict.getPixels():
            color = p.getColor()
            p.setColor(color.brighter())
        self.pict.write(OUTPUT + "testlighten.jpg")
        self.picttest1 = Picture(OUTPUT + "testlighten.jpg")
        self.picttest2 = Picture(PICTURES + "barb-lighten.jpg")
        self.assertEqual(self.picttest1.getWidth(), self.picttest2.getWidth(
        ), 'Widths are not the same (%s != %s)' % (self.picttest1.getWidth(), self.picttest2.getWidth()))
        self.assertEqual(self.picttest1.getHeight(), self.picttest2.getHeight(
#.........這裏部分代碼省略.........
開發者ID:NicMcPhee,項目名稱:jes,代碼行數:103,代碼來源:Test_Picture_BOOK.py


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