本文整理汇总了Python中Images.exportCGImageToPNGFileWithDestination方法的典型用法代码示例。如果您正苦于以下问题:Python Images.exportCGImageToPNGFileWithDestination方法的具体用法?Python Images.exportCGImageToPNGFileWithDestination怎么用?Python Images.exportCGImageToPNGFileWithDestination使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Images
的用法示例。
在下文中一共展示了Images.exportCGImageToPNGFileWithDestination方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exportImageWithMaskFromURLWithDestination
# 需要导入模块: import Images [as 别名]
# 或者: from Images import exportCGImageToPNGFileWithDestination [as 别名]
def exportImageWithMaskFromURLWithDestination(context, imageURL,
imagewidth, imageheight, bitsPerComponent,
theMaskingImageURL, maskwidth, maskheight):
imageBitsPerPixel = bitsPerComponent * 3
bytesPerRow = ((imagewidth * imageBitsPerPixel) + 7)/8
shouldInterpolate = True
imageDataProvider = CGDataProviderCreateWithURL(imageURL)
if imageDataProvider is None:
print >>sys.stderr, "Couldn't create Image Data provider!"
return
colorspace = Utilities.getTheCalibratedRGBColorSpace()
image = CGImageCreate(imagewidth, imageheight, bitsPerComponent,
imageBitsPerPixel, bytesPerRow, colorspace,
kCGImageAlphaNone, imageDataProvider,
None, shouldInterpolate,
kCGRenderingIntentDefault)
del imageDataProvider
if image is None:
print >>sys.stderr, "Couldn't create CGImageRef for this data!"
return
imageRect = CGRectMake(0.0,imageheight, imagewidth, imageheight)
# Draw the image.
CGContextDrawImage(context, imageRect, image)
# Now the mask.
maskDataProvider = CGDataProviderCreateWithURL(theMaskingImageURL)
if maskDataProvider is None:
print >>sys.stderr, "Couldn't create Image Data provider!"
return
mask = CGImageMaskCreate(maskwidth, maskheight, bitsPerComponent,
bitsPerComponent, maskwidth,
maskDataProvider, None, shouldInterpolate)
del maskDataProvider
if mask is None:
print >>sys.stderr, "Couldn't create CGImageRef for mask data!"
return
# Draw the mask below the image.
maskRect = CGRectMake(0.0, 0.0, maskwidth, maskheight)
CGContextDrawImage(context, maskRect, mask)
# Create a new CGImage object, the image, masked with mask.
imageMaskedWithImage = CGImageCreateWithMask(image, mask)
# Once the new image is created, we can release the image
# and the mask which make it up. Quartz retains what it needs
# for the new masked image.
del image
del mask
if imageMaskedWithImage is None:
print >>sys.stderr, "Couldn't create image masked with mask!"
return
imageRect = CGRectMake(imagewidth, imageheight/2, imagewidth, imageheight)
# Draw the masked image to the right of the image and its mask.
CGContextDrawImage(context, imageRect, imageMaskedWithImage)
# Of course this is a total hack.
outPath = "/tmp/imageout.png"
exportURL = CFURLCreateFromFileSystemRepresentation(None,
outPath, len(outPath), False)
if exportURL is not None:
Images.exportCGImageToPNGFileWithDestination(imageMaskedWithImage, exportURL)