0

I am creating an application in which many screenshots are taken, converted to NSData, and saved. With the current code I have, everything works with no errors, but running

bitmap.representationUsingType(NSBitmapImageFileType.NSJPEGFileType, properties: [NSImageCompressionFactor:0.1])

takes a very long time.

Here is the code:

let ref=CGWindowListCreateImage(CGRect.infinite, CGWindowListOption.OptionAll, 0, CGWindowImageOption.Default)
let bitmap=NSBitmapImageRep(CGImage: CGBitmapContextCreateImage(context)!)
let data=bitmap.representationUsingType(NSBitmapImageFileType.NSJPEGFileType, properties: [NSImageCompressionFactor:0.1])

Is there a more efficient or faster way of accomplishing this?

B Person
  • 33
  • 6
  • What's your question? What profiling have you done? What have you tried? – Wain Nov 11 '15 at 00:21
  • I have tried making an NSImage but converting that NSImage to NSData is always slow. – B Person Nov 11 '15 at 00:33
  • are you doing all this on the main thread? – R Menke Nov 11 '15 at 01:32
  • Yes and I have tested how fast the script runs without the representationusingtype line and it is significantly faster. – B Person Nov 11 '15 at 02:02
  • 1
    I would let it run on a background queue. I do not know why you need the screenshots and why they need to be done as quickly as possible. Freeing up the main queue will not improve speed. But it will allow the user to continue using the app while the heavy stuff happens on a separate thread. p.s. use `@USERNAME` to address another user in comments, then they get a notification. – R Menke Nov 11 '15 at 02:21

0 Answers0