Iphone上开发ARToolkit应用的注意事项总结.doc_第1页
Iphone上开发ARToolkit应用的注意事项总结.doc_第2页
Iphone上开发ARToolkit应用的注意事项总结.doc_第3页
Iphone上开发ARToolkit应用的注意事项总结.doc_第4页
Iphone上开发ARToolkit应用的注意事项总结.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Iphone上开发ARToolkit应用的注意事项总结文章分类:移动开发 原创文章,欢迎转载,转载时务必注明原文地址及作者 1. 如何调整uiimage的大小 C代码 1. /改变图片到指定的尺寸 2. -(UIImage*)resizedImage:(UIImage*)inImageinRect:(CGRect)thumbRect 3. 4. /Createsabitmap-basedgraphicscontextandmakesitthecurrentcontext. 5. UIGraphicsBeginImageContext(thumbRect.size); 6. inImagedrawInRect:thumbRect; 7. returnUIGraphicsGetImageFromCurrentImageContext(); 8. /改变图片到指定的尺寸-(UIImage*)resizedImage:(UIImage*)inImage inRect:(CGRect)thumbRect / Creates a bitmap-based graphics context and makes it the current context.UIGraphicsBeginImageContext(thumbRect.size);inImage drawInRect:thumbRect;return UIGraphicsGetImageFromCurrentImageContext();2. 如何取得uiimage图像中的RGB数据 C代码 1. /uiimage编码成ARGB 2. -(CGContextRef)createARGBBitmapContextFromImage:(CGImageRef)inImage 3. 4. CGContextRefcontext=NULL; 5. CGColorSpaceRefcolorSpace; 6. void*bitmapData; 7. intbitmapByteCount; 8. intbitmapBytesPerRow; 9. 10. /Getimagewidth,height.Wellusetheentireimage. 11. size_tpixelsWide=CGImageGetWidth(inImage); 12. size_tpixelsHigh=CGImageGetHeight(inImage); 13. /intpixelsWide,pixelsHigh; 14. /ar2VideoGetSize(gVid,&pixelsWide,&pixelsHigh); 15. 16. /Declarethenumberofbytesperrow.Eachpixelinthebitmapinthis 17. /exampleisrepresentedby4bytes;8bitseachofred,green,blue,and 18. /alpha. 19. bitmapBytesPerRow=(pixelsWide*4); 20. bitmapByteCount=(bitmapBytesPerRow*pixelsHigh); 21. 22. /UsethegenericRGBcolorspace. 23. colorSpace=CGColorSpaceCreateDeviceRGB(); 24. /colorSpace=CGImageGetColorSpace(inImage); 25. 26. if(colorSpace=NULL) 27. 28. fprintf(stderr,Errorallocatingcolorspacen); 29. returnNULL; 30. 31. 32. /Allocatememoryforimagedata.Thisisthedestinationinmemory 33. /whereanydrawingtothebitmapcontextwillberendered. 34. bitmapData=malloc(bitmapByteCount); 35. if(bitmapData=NULL) 36. 37. fprintf(stderr,Memorynotallocated!); 38. CGColorSpaceRelease(colorSpace); 39. returnNULL; 40. 41. 42. /Createthebitmapcontext.Wewantpre-multipliedARGB,8-bits 43. /percomponent.Regardlessofwhatthesourceimageformatis 44. /(CMYK,Grayscale,andsoon)itwillbeconvertedovertotheformat 45. /specifiedherebyCGBitmapContextCreate. 46. context=CGBitmapContextCreate(bitmapData, 47. pixelsWide, 48. pixelsHigh, 49. 8,/bitspercomponent 50. bitmapBytesPerRow, 51. colorSpace, 52. kCGImageAlphaPremultipliedFirst);/kCGImageAlphaNone 53. if(context=NULL) 54. 55. free(bitmapData); 56. fprintf(stderr,Contextnotcreated!); 57. 58. 59. /Makesureandreleasecolorspacebeforereturning 60. CGColorSpaceRelease(colorSpace); 61. 62. returncontext; 63. /uiimage编码成ARGB- (CGContextRef) createARGBBitmapContextFromImage:(CGImageRef) inImage CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; / Get image width, height. Well use the entire image. size_t pixelsWide = CGImageGetWidth(inImage); size_t pixelsHigh = CGImageGetHeight(inImage);/int pixelsWide, pixelsHigh;/ar2VideoGetSize(gVid, &pixelsWide, &pixelsHigh); / Declare the number of bytes per row. Each pixel in the bitmap in this / example is represented by 4 bytes; 8 bits each of red, green, blue, and / alpha. bitmapBytesPerRow = (pixelsWide * 4); bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); / Use the generic RGB color space. colorSpace = CGColorSpaceCreateDeviceRGB();/colorSpace = CGImageGetColorSpace(inImage); if (colorSpace = NULL) fprintf(stderr, Error allocating color spacen); return NULL; / Allocate memory for image data. This is the destination in memory / where any drawing to the bitmap context will be rendered. bitmapData = malloc( bitmapByteCount ); if (bitmapData = NULL) fprintf (stderr, Memory not allocated!); CGColorSpaceRelease( colorSpace ); return NULL; / Create the bitmap context. We want pre-multiplied ARGB, 8-bits / per component. Regardless of what the source image format is / (CMYK, Grayscale, and so on) it will be converted over to the format / specified here by CGBitmapContextCreate. context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8, / bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedFirst);/ kCGImageAlphaNone if (context = NULL) free (bitmapData); fprintf (stderr, Context not created!); / Make sure and release colorspace before returning CGColorSpaceRelease( colorSpace ); return context;3. 如何识别多个marker文件 C代码 1. /配置ar识别marker参数 2. staticintsetupMarker(constchar*patt_name,int*patt_id,ARHandle*arhandle,ARPattHandle*pattHandle_p) 3. 4. /此处修改支持识别多个marker文件 5. if(*pattHandle_p=NULL) 6. *pattHandle_p=arPattCreateHandle(); 7. if(*pattHandle_p=NULL) 8. fprintf(stderr,setupMarker():Error:arPattCreateHandle.n); 9. return(FALSE); 10. 11. arPattAttach(arhandle,*pattHandle_p); 12. 13. 14. if(*patt_id=arPattLoad(*pattHandle_p,patt_name)0) 15. fprintf(stderr,setupMarker():Errorloadingpatternfile%s.n,patt_name); 16. arPattDeleteHandle(*pattHandle_p); 17. return(FALSE); 18. 19. 20. return(TRUE); 21. /配置ar识别marker参数static int setupMarker(const char *patt_name, int *patt_id, ARHandle *arhandle, ARPattHandle *pattHandle_p)/此处修改支持识别多个marker文件if (*pattHandle_p = NULL) *pattHandle_p = arPattCreateHandle();if (*pattHandle_p = NULL) fprintf(stderr, setupMarker(): Error: arPattCreateHandle.n);return (FALSE);arPattAttach(arhandle, *pattHandle_p); if (*patt_id = arPattLoad(*pattHandle_p, patt_name) markerInfo0.vertexgARHandle-markerInfo0. vertex5. 如何绘画识别出的marker的外框以及对于的图片背景 C代码 1. /画出marker的外框 2. -(void)drawMarkerRect 3. CGContextRefcontext=UIGraphicsGetCurrentContext(); 4. CGContextSetStrokeColorWithColor(context,UIColorgreenColor.CGColor);/颜色 5. CGContextSetLineWidth(context,2.0);/线宽 6. /画线 7. CGContextMoveToPoint(context,x1,y1); 8. CGContextAddLineToPoint(context,x2,y2); 9. CGContextAddLineToPoint(context,x3,y3); 10. CGContextAddLineToPoint(context,x4,y4); 11. CGContextAddLineToPoint(context,x1,y1); 12. CGContextStrokePath(context); 13. 14. /描绘识别marker外框的模式 15. self.backgroundColor=UIColorcolorWithPatternImage:mimage;/画出marker的外框- (void)drawMarkerRect CGContextRef context = UIGraphicsGetCurrentContext();CGContextSetStrokeColorWithColor(context, UIColor greenColor.CGColor);/颜色CGContextSetLineWidth(context, 2.0);/线宽/画线CGContextMoveToPoint(context,x1, y1);CGContextAddLineToPoint(context, x2, y2);CGContextAddLineToPoint(context, x3, y3);CGContextAddLineToPoint(context, x4, y4);CGContextAddLineToPoint(context, x1, y1);CGContextStrokePath(context);/描绘识别marker外框的模式self.backgroundColor = UIColor colorWithPatternImage:mimage;6. 如何利用NSTimer来实现异步调用 C代码 1. /延迟加载视频,让画出marker的画面显示一下 2. mTimer=NSTimerscheduledTimerWithTimeInterval:INTERVAL_SECtarget:selfselector:selector(playMovie:)userInfo:nilrepeats:NO; 3. /播放视频 4. -(void)playMovie:(NSTimer*)timer 5. viewControllerplayMovie:currentTag.movie; 6. mTimerrelease; 7. mTimer=nil; 8. /延迟加载视频,让画出marker的画面显示一下mTimer = NSTimer scheduledTimerWithTimeInterval:INTERVAL_SEC target:self selector:selector(playMovie:) userInfo:nil repeats:NO;/播放视频- (void)playMovie:(NSTimer *)timer viewController playMovie:currentTag.movie;mTimer release;mTimer = nil;7. 如何保存当前图片到图片文件夹 C代码 1. /保持图片到照片文件夹 2. -(void)saveToPhotosAlbum:(UIImage*)image 3. CGContextRefcontext=UIGraphicsGetCurrentContext(); 4. UIImageWriteToSavedPhotosAlbum(image,self,selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:),context); 5. UIGraphicsEndImageContext(); 6. 7. 8. /保存图片时的回调 9. -(void)imageSa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论