选择和定制相册中的图像

//如果要将图片保存到 Documents中 则用下面这个函数
//并且在紧挨着的下一个函数里加上  
//[UIImagePNGRepresentation(image) writeToFile:[self findUniqueSavePath] atomically:YES];
//这句话
- (NSString *) findUniqueSavePath
{
	int i = 1;
	NSString *path; 
	do 
    {
	    path = [NSString stringWithFormat:@"%@/Documents/IMAGE_%04d.PNG", NSHomeDirectory(), i++];
        
	} while ([[NSFileManager defaultManager] fileExistsAtPath:path]);
	
	return path;
}
- (void)imagePickerController:(UIImagePickerController *)picker 

        didFinishPickingMediaWithInfo:(NSDictionary *)info
{
	CFShow(info);
    
    SETIMAGE([info objectForKey:@"UIImagePickerControllerEditedImage"]);
    
	[self dismissModalViewControllerAnimated:YES]; 
    
	[picker release];
}
//  告诉委托用户选择了一张图片 这种过时的方法只支持静态图片采集。
//替换方法,imagePickerController:didFinishPickingMediaWithInfo:, 支持采摘电影以及静态图片

- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image 
                  editingInfo:(NSDictionary *)editingInfo  
{
	NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:editingInfo];
    
	[dict setObject:image forKey:@"UIImagePickerControllerEditedImage"];
    
	[self imagePickerController:picker didFinishPickingMediaWithInfo:dict];
}
- (void) pickImage: (id) sender
{
	UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    
	ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
    
    /* UIImagePickerControllerSourceTypePhotoLibrary,    // 设备的图片库
       UIImagePickerControllerSourceTypeCamera,          // 设备的摄像头
       UIImagePickerControllerSourceTypeSavedPhotosAlbum // 保存的图像*/
    
	ipc.delegate = self;
    
	ipc.allowsImageEditing = YES;
    
	[self presentModalViewController:ipc animated:YES];	 
    
    //presentModalViewController显示半透明的一个view
}
- (void) viewDidLoad
{
	self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
    
	self.navigationItem.rightBarButtonItem = BARBUTTON(@"Pick", @selector(pickImage:));
    
	self.title = @"Image Picker";
}

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值