本文整理匯總了Python中PIL.ImageFile._save方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageFile._save方法的具體用法?Python ImageFile._save怎麽用?Python ImageFile._save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.ImageFile
的用法示例。
在下文中一共展示了ImageFile._save方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _save
# 需要導入模塊: from PIL import ImageFile [as 別名]
# 或者: from PIL.ImageFile import _save [as 別名]
def _save(im, fp, filename):
if im.mode[0] != "F":
im = im.convert('F')
hdr = makeSpiderHeader(im)
if len(hdr) < 256:
raise IOError("Error creating Spider header")
# write the SPIDER header
try:
fp = open(filename, 'wb')
except:
raise IOError("Unable to open %s for writing" % filename)
fp.writelines(hdr)
rawmode = "F;32NF" # 32-bit native floating point
ImageFile._save(im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, 0, 1))])
fp.close()
示例2: _save
# 需要導入模塊: from PIL import ImageFile [as 別名]
# 或者: from PIL.ImageFile import _save [as 別名]
def _save(im, fp, filename):
if im.mode[0] != "F":
im = im.convert('F')
hdr = makeSpiderHeader(im)
if len(hdr) < 256:
raise IOError("Error creating Spider header")
# write the SPIDER header
fp.writelines(hdr)
rawmode = "F;32NF" # 32-bit native floating point
ImageFile._save(im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, 0, 1))])
示例3: _save_spider
# 需要導入模塊: from PIL import ImageFile [as 別名]
# 或者: from PIL.ImageFile import _save [as 別名]
def _save_spider(im, fp, filename):
# get the filename extension and register it with Image
ext = os.path.splitext(filename)[1]
Image.register_extension(SpiderImageFile.format, ext)
_save(im, fp, filename)
# --------------------------------------------------------------------
示例4: _save
# 需要導入模塊: from PIL import ImageFile [as 別名]
# 或者: from PIL.ImageFile import _save [as 別名]
def _save(im, fp, filename):
if im.mode[0] != "F":
im = im.convert("F")
hdr = makeSpiderHeader(im)
if len(hdr) < 256:
raise OSError("Error creating Spider header")
# write the SPIDER header
fp.writelines(hdr)
rawmode = "F;32NF" # 32-bit native floating point
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, 0, 1))])
示例5: _save_spider
# 需要導入模塊: from PIL import ImageFile [as 別名]
# 或者: from PIL.ImageFile import _save [as 別名]
def _save_spider(im, fp, filename):
# get the filename extension and register it with Image
ext = os.path.splitext(filename)[1]
Image.register_extension(SpiderImageFile.format, ext)
_save(im, fp, filename)
# --------------------------------------------------------------------
示例6: _save
# 需要導入模塊: from PIL import ImageFile [as 別名]
# 或者: from PIL.ImageFile import _save [as 別名]
def _save(im, fp, filename, check=0):
try:
rawmode, bits, colors = SAVE[im.mode]
except KeyError:
raise IOError("cannot write mode %s as BMP" % im.mode)
if check:
return check
info = im.encoderinfo
dpi = info.get("dpi", (96, 96))
# 1 meter == 39.3701 inches
ppm = tuple(map(lambda x: int(x * 39.3701), dpi))
stride = ((im.size[0]*bits+7)//8+3) & (~3)
header = 40 # or 64 for OS/2 version 2
offset = 14 + header + colors * 4
image = stride * im.size[1]
# bitmap header
fp.write(b"BM" + # file type (magic)
o32(offset+image) + # file size
o32(0) + # reserved
o32(offset)) # image data offset
# bitmap info header
fp.write(o32(header) + # info header size
o32(im.size[0]) + # width
o32(im.size[1]) + # height
o16(1) + # planes
o16(bits) + # depth
o32(0) + # compression (0=uncompressed)
o32(image) + # size of bitmap
o32(ppm[0]) + o32(ppm[1]) + # resolution
o32(colors) + # colors used
o32(colors)) # colors important
fp.write(b"\0" * (header - 40)) # padding (for OS/2 format)
if im.mode == "1":
for i in (0, 255):
fp.write(o8(i) * 4)
elif im.mode == "L":
for i in range(256):
fp.write(o8(i) * 4)
elif im.mode == "P":
fp.write(im.im.getpalette("RGB", "BGRX"))
ImageFile._save(im, fp, [("raw", (0, 0)+im.size, 0,
(rawmode, stride, -1))])
#
# --------------------------------------------------------------------
# Registry