您的位置:首页 > 其它

Week 4: Ways to Get to iPhone’s Camera Frames

2011-07-28 12:42 239 查看

Week4:WaystoGettoiPhone’sCameraFrames

March21,2010

Everythingfromthisweekyou’llfindinnextweek’sarticle:Week5:WaystoGettoiPhone’sCameraFrames(Continued).

原文:http://durchblickapp.wordpress.com/2010/03/28/week-5-ways-to-get-to-iphone%e2%80%99s-camera-frames-continued/

Week5:WaystoGettoiPhone’sCameraFrames(Continued)

March28,2010

ThesupportedwayofusingtheiPhone’scameraisbytakingphotosandvideosonthesupporteddeviceswiththestandardUIImagePickerControllerandthensavethemtodiskforfurtherusage.ThesameUIImagePickerControllerisalsousedforpickingexistingmedia.
Post-processingalreadytakenmediadoesn’tmakesenseforanARapp.
AnARappwhichdoesimageprocessingneeds
cameraframesatarelativelyhighfrequencyf1forimageprocessingand
thescreenfilledwithcameraframesataveryhighfrequencyf2tocreatetheillusionof“lookingthroughthedeviceintotherealworld”.
TheResolutiondoesn’tmatterthatmuchforimageprocessingneitherfordisplayingonthedevice’sscreenwithitssmallresolution.
Regardlesswhichmethodisused,fillingthescreenwithcameraframesnevercomesuptotheneededfrequencyf2ofabout30-60Hz.SowedisplaythepreviewoftheUIImagePickerController.



ImagePickerController’scontrols
SinceiPhoneOS3.1it’spossibletohidethecontrols.



ImagePickerController’scontrolsdisabled
Nowthereisablackbaratthebottom(spacethecameracontrolsonceoccupied)withaheightof56px.Tocoverthatwecanstretchthecamera’sviewwithanaffinematrixtransform.
idiom:stretchvertically


ImagePickerController’sviewstretchedvertically
Advantage:noimageinformationloss
Disadvantage:distortedaspectration

idiom:scaleproportionally


ImagePickerController’sviewscaled
Advantage:keepaspectratio
Disadvantage:loseimageinformationonthesideduetozoomeffect

Decision:useidiom2foritsaspectratiokeeping
(480-56)->1
480->1.132075471698113(~13%scale)
Unfortunatelywecan’tlowerdisadvantagebydistributethelossonbothsides(notonlyrightside),sincetranslationdoesn’tseemtoapply.Wewouldhave:
320*1.132075471698113=362.26415094339616=~362
362–320=42pxlossonrightside=>move21pxtotheleft
Note:thetransformwillapplytoanypicturestakenby-takePicture
Nowwehaveascreenfuloftherealworldatahighfrequency.
Tocapturethecameraframesatarelativelyhighfrequencyf1forimageprocessingtherearebasicallythreeways:
UIImagePickerController’smethod-takePicture
ThisisawayoftakingpicturesprogrammaticallyintroducediniPhoneOS3.1.ButitstillrequirestheheavyuserprocessandaftersometestsIfoundafrequencyofabout1Hzbutf1mustbehigher.Alsotheimagewasinfullcameraresolution(about3MP)andIranintomemoryconstraints.
HackswithprivateAPI
Idon’thaveanyexperiencewiththisandwon’tconcentrateonit.Ithinkit’sneveragoodwaytogo.
“PrivateAPI”functionUIGetScreenImage
It’sprivateAPIbutApplehasstartedallowingtheuseofthisfunctionintheendof2009.MaybeitwillbreakinafuturereleaseofiPhoneOSandmaybeyoustillgotrejectedfromtheAppStore.MaybeApplesoonwillprovideapublicAPI.
Sinceitsimplycapturesthecurrentscreencontent,ifyouoverlayUIinframetitwillbecapturedtooinframet+1.ThepartofthescreenyouwanttoprocessmustremainclearfromUIandshowtheoriginalpicture.
Tousethisfunctionconveniently,thefollowingworkwasnecessary.
01
@implementation
UIImage(DBAdditions)
02
03
+(UIImage*)imageWithScreenContents{
04
//Capturesthecurrentscreencontentinscreenresolution.
05
//-"PrivateAPI"
06
//-returnsNULLinsimulator
07
//-Thememorymanagement"CreateRule"statesthateveryfunctionwith"Create"or"Copy"embeddedinthename
08
//returnaretainedobject.Allothersareautoreleased.However,UIGetScreenImagereturnsaretainedCGImageRef.
09
//Becauseit’ssupposedtobeaprivateAPI,theyweren'tcarefulwiththename.
10
//Declarationinsidemethodsinceit'stheonlyscopeweneedthisfunction.
11
extern
CGImageRefUIGetScreenImage(
void
);
12
//keyword'extern':clarifythatdefinitionisinotherfile
13
//argument'void':emptyargumentlistwouldmeananynumberofargumentsofanytypeinC
14
15
CGImageRefscreenImage=UIGetScreenImage();
16
if
(screenImage!=
NULL
){
17
UIImage*image=[UIImageimageWithCGImage:screenImage];
18
CGImageRelease(screenImage);
19
return
image;
20
}
21
return
nil
;
22
}
23
24
@end
Firsttestsbyusingthisinabackgroundthreadandsavingtheimagestothephotoslibraryweresuccessful.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: