def exportColorRampImageWithQT(context): width = 256 height = 256 bitsPerComponent = 8 bitsPerPixel = 24 bytesPerRow = width * 3 shouldInterpolate = True imageDataProvider = DataProvidersAndConsumers.createRGBRampDataProvider() if imageDataProvider is None: print >>sys.stderr, "Couldn't create Image Data provider!" return colorspace = Utilities.getTheCalibratedRGBColorSpace() image = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, kCGRenderingIntentDefault) del imageDataProvider if image is None: print >>sys.stderr, "Couldn't create CGImageRef for this data!" return rect = CGRectMake(0.0, 0.0, width, height) CGContextDrawImage(context, rect, image) # Of course this is a total hack. outPath = "/tmp/imageout.jpg" exportURL = CFURLCreateFromFileSystemRepresentation(None, outPath, len(outPath), False) if exportURL: exportCGImageToJPEGFile(image, exportURL)
def doColorRampImage(context): width = 256 height = 256 bitsPerComponent = 8 bitsPerPixel = 24 bytesPerRow = width * 3 shouldInterpolate = True imageDataProvider = DataProvidersAndConsumers.createRGBRampDataProvider() if imageDataProvider is None: print >>sys.stderr, "Couldn't create Image Data provider!" return colorspace = Utilities.getTheCalibratedRGBColorSpace() image = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, kCGRenderingIntentDefault) # No longer need the data provider. del imageDataProvider if image is None: print >>sys.stderr, "Couldn't create CGImageRef for this data!" return imageRect = CGRectMake(0.0, 0.0, width, height) # Draw the image. CGContextDrawImage(context, imageRect, image)
def exportColorRampImageWithQT(context): width = 256 height = 256 bitsPerComponent = 8 bitsPerPixel = 24 bytesPerRow = width * 3 shouldInterpolate = True imageDataProvider = DataProvidersAndConsumers.createRGBRampDataProvider() if imageDataProvider is None: print("Couldn't create Image Data provider!") return colorspace = Utilities.getTheCalibratedRGBColorSpace() image = Quartz.CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, Quartz.kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, Quartz.kCGRenderingIntentDefault) del imageDataProvider if image is None: print("Couldn't create CGImageRef for this data!") return rect = Quartz.CGRectMake(0.0, 0.0, width, height) Quartz.CGContextDrawImage(context, rect, image) # Of course this is a total hack. outPath = b"/tmp/imageout.jpg" exportURL = CFURLCreateFromFileSystemRepresentation( None, outPath, len(outPath), False) if exportURL: exportCGImageToJPEGFile(image, exportURL)
def doColorRampSubImage(context): # Start 4 scanlines from the top and 16 pixels from the left edge, # skip the last 40 scanlines of the image and the right # most 64 pixels. insetLeft = 16 insetTop = 4 insetRight = 64 insetBottom = 40 fullImageWidth = 256 fullImageHeight = 256 subImageWidth = fullImageWidth-insetLeft-insetRight subImageHeight = fullImageHeight-insetTop-insetBottom bitsPerComponent = 8 bitsPerPixel = 24 bytesPerRow = fullImageWidth * 3 shouldInterpolate = True imageSubRect = CGRectMake( insetLeft, insetTop, subImageWidth, subImageHeight) colorspace = Utilities.getTheCalibratedRGBColorSpace() if hasattr(Quartz, 'CGImageCreateWithImageInRect'): imageDataProvider = DataProvidersAndConsumers.createRGBRampDataProvider() if imageDataProvider is None: print >>sys.stderr, "Couldn't create Image Data provider!" return fullImage = CGImageCreate(fullImageWidth, fullImageHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, kCGRenderingIntentDefault) if fullImage is not None: image = CGImageCreateWithImageInRect(fullImage, imageSubRect) # release the full image since it is no longer required. del fullImage # If the image hasn't been created yet, this code uses the # customized data provider to do so. if image is None: imageDataProvider = createRGBRampSubDataProvider(imageSubRect) if imageDataProvider is None: print >>sys.stderr, "Couldn't create Image Data provider!" return # By supplying bytesPerRow, the extra data at the end of # each scanline and the beginning of the next is properly skipped. image = CGImageCreate(subImageWidth, subImageHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, kCGRenderingIntentDefault) # This code no longer needs the data provider. del imageDataProvider if image is None: print >>sys.stderr, "Couldn't create CGImageRef for this data!" return # Draw the subimage. rect = CGRectMake(0, 0, subImageWidth, subImageHeight) CGContextDrawImage(context, rect, image)