码迷,mamicode.com
首页 > 其他好文 > 详细

相册操作

时间:2015-03-12 20:33:27      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

/*

#pragma mark -点击图片显示大图-
-(void)addEnvironment:(int) index
{
    WZPreviewPictureViewController * pp = [[WZPreviewPictureViewController alloc] init];
    pp.urlString = [((NSString *)[self.datalist objectAtIndex:index]) changeBigImage];
    self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:pp animated:YES completion:nil];
    [pp release];
}



// 将图片转换为JPG格式的二进制数据上传
- (void)shangchuantupian
{
    NSData *data = UIImageJPEGRepresentation(self.productPic.image, 1); //将图片转换为JPG格式的二进制数据上传
    [_requestCommon setData:data withFileName:@"coupon.jpg" andContentType:@"image/jpeg" forKey:@"imgpath"];
}
- (void)actionSheet
{
    
#warning 系统版本高于 8.0 调用此方法
    UIAlertController *pictureSelectAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *takePhoto = [UIAlertAction actionWithTitle:JZLTakePhoto style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // 照相
        
        [self JZLTakePhotos];
    }];
    UIAlertAction *selectPhoto = [UIAlertAction actionWithTitle:JZLSelectPhoto style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // 从相册选择
        
        [self JZLSelectPhotos];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

    [pictureSelectAlert addAction:takePhoto];
    [pictureSelectAlert addAction:selectPhoto];
    [pictureSelectAlert addAction:cancel];

    [self presentViewController:pictureSelectAlert animated:YES completion:nil];
}
// 照相
- (void)JZLTakePhotos
{
    UIImagePickerController *_ipcCamera = [[UIImagePickerController alloc] init];
    _ipcCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
    _ipcCamera.delegate = self;
    _ipcCamera.allowsEditing = YES;
    [self presentViewController:_ipcCamera animated:YES completion:nil];
    [_ipcCamera release];
}
// 从相册选择
- (void)JZLSelectPhotos
{
    UIImagePickerController *_ipcPhoto = [[UIImagePickerController alloc] init];
    _ipcPhoto.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    _ipcPhoto.delegate = self;
    _ipcPhoto.allowsEditing = YES;
    [self presentViewController:_ipcPhoto animated:YES completion:nil];
    [_ipcPhoto release];
}
#pragma mark ----UIImagePickerControllerDelegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSLog(@"%@", info);
    
    UIImage *img = nil;
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // 相机获得
        
        //如果是 来自照相机的image,那么先保存UIImagePickerControllerEditedImage
        UIImage *OriginalImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        UIImageWriteToSavedPhotosAlbum(OriginalImage, self, nil, nil);
        
        // 获得编辑过的图片
        img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        
    } else if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { // 相册获得
        
        img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    }
    
    UIImage *pressedImg = nil;
    // 压缩
    if (img.size.width >300 || img.size.height > 300) {
        
        float scale = 300.0 / img.size.width;
        CGSize size = CGSizeMake(img.size.width * scale, img.size.height * scale);
        
        pressedImg = [self imageWithImageSample:img scaleToSize:size];
    } else {
        
        pressedImg = img;
    }
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
        [self.productPic setImage:pressedImg];
    }];
}
// 照片压缩
- (UIImage *)imageWithImageSample:(UIImage *)image scaleToSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    
    UIImage *pressedIMG = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return pressedIMG;
}

*/

相册操作

标签:

原文地址:http://www.cnblogs.com/jzlblog/p/4333303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!