zoukankan      html  css  js  c++  java
  • 相册操作

    /*

    #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;
    }

    */

  • 相关阅读:
    python:JSON的两种常用编解码方式实例解析
    Python中的map与reduce函数简介
    Python初学者的几个迷惑点
    Python Numpy中数据的常用的保存与读取方法
    python全栈 day03 操作系统 -- 摘要
    python全栈 day02 计算机原理 -- 硬件
    Python作业之购物商城
    Lesson one of python
    总体设计
    ASP.Net页面上用户控件相互调用的方法
  • 原文地址:https://www.cnblogs.com/jzlblog/p/4333303.html
Copyright © 2011-2022 走看看