Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. - (NSSize)pixelSize
  2. {
  3. CGImageRef CGImage = [self CGImageForProposedRect:nil context:nil hints:nil];
  4. NSBitmapImageRep *bmp = [[NSBitmapImageRep alloc] initWithCGImage:CGImage];
  5. return NSMakeSize(bmp.pixelsWide, bmp.pixelsHigh);
  6. }
  7.  
  8.  
  9. NSColor *color = [NSColor redColor];
  10. NSPDFImageRep* rep = self.representations.lastObject;
  11. return [NSImage imageWithSize:self.pixelSize flipped:NO drawingHandler:^BOOL (NSRect dstRect)
  12. {
  13.  
  14. [[NSGraphicsContext currentContext] saveGraphicsState];
  15. CGFloat lineWidth = 1.;
  16. NSBezierPath *strokePath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(dstRect, lineWidth/2., lineWidth/2.)];
  17. [[NSColor whiteColor] set];
  18. [strokePath setLineWidth:lineWidth];
  19. [strokePath fill];
  20.  
  21. [color set];
  22. [rep drawInRect:dstRect fromRect:NSZeroRect operation:NSCompositeSourceIn fraction:1 respectFlipped:YES hints:@{NSImageHintInterpolation: @(NSImageInterpolationHigh)}];
  23.  
  24. [color set];
  25. [strokePath stroke];
  26. [[NSGraphicsContext currentContext] restoreGraphicsState];
  27.  
  28. return YES;
  29. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement