Sunday, 15 May 2011

osx - Partial screen capture in Objective C -



osx - Partial screen capture in Objective C -

i have been trying figure out how create os x routine in objective c that:

run in background (separate thread) ,

repeatedly (timed or when criteria met) captures several defined subsets of specified window/screen (i.e. without user interaction) ,

save images specified path.

similar output of "pre-programmed loop of cmd-shift-4 + mousedown-drag".

neither sonofgrab nor screensnapshot mac developer library seem indicate how done, suspect cgimageref one/the(?) way go it.

does know how it?

are there other possible ways besides cgimageref solve problem? illustration done via command-line tools , nstask?

if so, advantages/disadvantages different methods in terms of speed , complexity?

assuming have logic required screengrab (which can see in sonofgrab), utilize dispatch queue or timer job.

void mytakescreengrab(); dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_background, 0); dispatch_source_t timersrc = dispatch_source_create(dispatch_source_type_timer,0,0,queue); dispatch_source_set_timer(timersrc, dispatch_time(dispatch_time_now,0) /* start on */, seconds_per_grab * nsec_per_sec /* interval */, nsec_per_sec /* leeway */); dispatch_source_set_event_handler_f(timersrc, mytakescreengrab); dispatch_resume(timersrc);

you can utilize nstimer well.

-(void)setup { _timer = [[nstimer scheduledtimerwithtimeinterval: (nstimerinterval)seconds_per_grab target: self selector: @selector(takescreegrabonbgthread:) userinfo: @{ @"folderpath" : myfolderpath(), @"imagesettings" : mycgimagesettings() } repeats: yes]; [_timer fire]; } -(void)takescreengrabonbgthread:(id)userinfo { [self performselectorinbackground:@selector(takescreengrabblocking:) withobject:userinfo]; } -(void)takescreengrabblocking:(id)userinfo { mytakescreengab(userinfo); }

to utilize terminal this, command you're looking screencapture(1).

objective-c osx xcode4 core-graphics screenshot

No comments:

Post a Comment