ipad开发从图片库中加载图片

在设计Ipad项目时从图片库中加载图片好处是用户可以通过数据线以及mac电脑上的itunes或预览程序 同步图片信息,这样可以方便图片的管理,应用程序从图片库获取图片,可以通过如下方法:


UIImagePickerController *ipc = [[UIImagePickerController allocinit];

ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary; //图片库的源

ipc.delegate = self;  //代理为self 可见我们应该把用户pick的相关动作处理在当前类中实现,实现代理的协议UIImagePickerControllerDelegate

ipc.allowsImageEditing = NO; //禁止编辑

[self presentModalViewController:ipc animated:YES] ; //弹出模式对话框 


之后就是对用户选取的处理了

@interface TestBedViewController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate>

@end


@implementation TestBedViewController


// 3.0-3.1 提供

- (void) setAllowsEditing:(BOOL)doesAllow forPicker:(UIImagePickerController *) ipc

{

SEL allowsSelector;

if ([ipc respondsToSelector:@selector(setAllowsEditing:)]) allowsSelector = @selector(setAllowsEditing:);

NSMethodSignature *ms = [ipc methodSignatureForSelector:allowsSelector];

NSInvocation *inv = [NSInvocation invocationWithMethodSignature:ms];

[inv setTarget:ipc];

[inv setSelector:allowsSelector];

[inv setArgument:&doesAllow atIndex:2];

[inv invoke];

}


//  2.x 提供  当用户选取完成一副图片库中的图片保存到字典中

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

{

NSDictionary *dict = [NSDictionary dictionaryWithObject:imageforKey:@"UIImagePickerControllerOriginalImage"];

[self imagePickerController:picker didFinishPickingMediaWithInfo:dict];

}


// 如果用户取消

- (void) imagePickerControllerDidCancel: 

(UIImagePickerController *)picker

{

[self dismissModalViewControllerAnimated:YES];

[picker release];

}

//从字典获取图片并显示到当前窗口,同时关闭模态窗口 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

SETIMAGE([info objectForKey:@"UIImagePickerControllerOriginalImage"]);

[self dismissModalViewControllerAnimated:YES];

[picker release];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值