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


Python Image.getmodebase方法代碼示例

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


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

示例1: getcolor

# 需要導入模塊: from lib.pil import Image [as 別名]
# 或者: from lib.pil.Image import getmodebase [as 別名]
def getcolor(color, mode):
	# same as getrgb, but converts the result to the given mode
	color = getrgb(color)
	if mode == "RGB":
		return color
	if mode == "RGBA":
		r, g, b = color
		return r, g, b, 255
	if Image.getmodebase(mode) == "L":
		r, g, b = color
		return (r*299 + g*587 + b*114)/1000
	return color
開發者ID:TheArchives,項目名稱:blockBox,代碼行數:14,代碼來源:ImageColor.py

示例2: __init__

# 需要導入模塊: from lib.pil import Image [as 別名]
# 或者: from lib.pil.Image import getmodebase [as 別名]
	def __init__(self, image, size=None):
		if hasattr(image, "mode") and hasattr(image, "size"):
			mode = image.mode
			size = image.size
		else:
			mode = image
			image = None
		if mode not in ["1", "L", "P", "RGB"]:
			mode = Image.getmodebase(mode)
		self.image = Image.core.display(mode, size)
		self.mode = mode
		self.size = size
		if image:
			self.paste(image)
開發者ID:TheArchives,項目名稱:blockBox,代碼行數:16,代碼來源:ImageWin.py

示例3: show

# 需要導入模塊: from lib.pil import Image [as 別名]
# 或者: from lib.pil.Image import getmodebase [as 別名]
	def show(self, image, **options):

		# save temporary image to disk
		if image.mode[:4] == "I;16":
			# @PIL88 @PIL101
			# "I;16" isn't an 'official' mode, but we still want to
			# provide a simple way to show 16-bit images.
			base = "L"
			# FIXME: auto-contrast if max() > 255?
		else:
			base = Image.getmodebase(image.mode)
		if base != image.mode and image.mode != "1":
			image = image.convert(base)

		self.show_image(image, **options)
開發者ID:TheArchives,項目名稱:blockBox,代碼行數:17,代碼來源:ImageShow.py

示例4: _save

# 需要導入模塊: from lib.pil import Image [as 別名]
# 或者: from lib.pil.Image import getmodebase [as 別名]
def _save(im, fp, filename):

	if _imaging_gif:
		# call external driver
		try:
			_imaging_gif.save(im, fp, filename)
			return
		except IOError:
			pass # write uncompressed file

	try:
		rawmode = RAWMODE[im.mode]
		imOut = im
	except KeyError:
		# convert on the fly (EXPERIMENTAL -- I'm not sure PIL
		# should automatically convert images on save...)
		if Image.getmodebase(im.mode) == "RGB":
			imOut = im.convert("P")
			rawmode = "P"
		else:
			imOut = im.convert("L")
			rawmode = "L"

	# header
	for s in getheader(imOut, im.encoderinfo):
		fp.write(s)

	flags = 0

	try:
		interlace = im.encoderinfo["interlace"]
	except KeyError:
		interlace = 1

	# workaround for @PIL153
	if min(im.size) < 16:
		interlace = 0

	if interlace:
		flags = flags | 64

	try:
		transparency = im.encoderinfo["transparency"]
	except KeyError:
		pass
	else:
		# transparency extension block
		fp.write("!" +
				 chr(249) +			 # extension intro
				 chr(4) +			   # length
				 chr(1) +			   # transparency info present
				 o16(0) +			   # duration
				 chr(int(transparency)) # transparency index
				 + chr(0))

	# local image header
	fp.write("," +
			 o16(0) + o16(0) +		  # bounding box
			 o16(im.size[0]) +		  # size
			 o16(im.size[1]) +
			 chr(flags) +			   # flags
			 chr(8))					# bits

	imOut.encoderconfig = (8, interlace)

	ImageFile._save(imOut, fp, [("gif", (0,0)+im.size, 0, rawmode)])

	fp.write("\0") # end of image data

	fp.write(";") # end of file

	try:
		fp.flush()
	except: pass
開發者ID:TheArchives,項目名稱:blockBox,代碼行數:76,代碼來源:GifImagePlugin.py


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