本文整理汇总了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