Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Core Image route would be the most reliable. It's actually not very complicated, I've posted a sample below. If you know none of your images will be flipped then you can remove the transform code. The main thing to be careful of is that the conversion from <code>NSImage</code> to <code>CIImage</code> can be expensive performance-wise, so you should ensure you cache the <code>CIImage</code> if possible and don't re-create it during each drawing operation.</p> <pre><code>CIImage* ciImage = [[CIImage alloc] initWithData:[yourImage TIFFRepresentation]]; if ([yourImage isFlipped]) { CGRect cgRect = [ciImage extent]; CGAffineTransform transform; transform = CGAffineTransformMakeTranslation(0.0,cgRect.size.height); transform = CGAffineTransformScale(transform, 1.0, -1.0); ciImage = [ciImage imageByApplyingTransform:transform]; } CIFilter* filter = [CIFilter filterWithName:@"CIColorInvert"]; [filter setDefaults]; [filter setValue:ciImage forKey:@"inputImage"]; CIImage* output = [filter valueForKey:@"outputImage"]; [output drawAtPoint:NSZeroPoint fromRect:NSRectFromCGRect([output extent]) operation:NSCompositeSourceOver fraction:1.0]; </code></pre> <p>Note: release/retain memory management is left as an exercise, the code above assumes garbage collection.</p> <p>If you want to render the image at an arbitrary size, you could do the following:</p> <pre><code>NSSize imageSize = NSMakeSize(1024,768); //or whatever size you want [yourImage setSize:imageSize]; [yourImage lockFocus]; NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, imageSize.width, imageSize.height)]; [yourImage unlockFocus]; CIImage* image = [CIImage imageWithData:[bitmap TIFFRepresentation]]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload