本文整理匯總了Python中Picture.getPixels方法的典型用法代碼示例。如果您正苦於以下問題:Python Picture.getPixels方法的具體用法?Python Picture.getPixels怎麽用?Python Picture.getPixels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Picture
的用法示例。
在下文中一共展示了Picture.getPixels方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Test_Picture_GIF
# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import getPixels [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,
#.........這裏部分代碼省略.........
示例2: Test_Picture_BOOK
# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import getPixels [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(
#.........這裏部分代碼省略.........
示例3: Test_Picture_BMP
# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import getPixels [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())
#.........這裏部分代碼省略.........