标签:
代码如下 | 复制代码 |
#pragma mark 从用户相册获取活动图片 - (void)pickImageFromAlbum { imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical; imagePicker.allowsEditing = YES; [self presentModalViewController:imagePicker animated:YES]; } |
代码如下 | 复制代码 |
#pragma mark 从摄像头获取活动图片 - (void)pickImageFromCamera { imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical; imagePicker.allowsEditing = YES; [self presentModalViewController:imagePicker animated:YES]; } |
代码如下 | 复制代码 |
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{ UIImage *image= [info objectForKey:@"UIImagePickerControllerOriginalImage"]; if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); } theImage = [UtilMethod imageWithImageSimple:image scaledToSize:CGSizeMake(120.0, 120.0)]; UIImage *midImage = [UtilMethod imageWithImageSimple:image scaledToSize:CGSizeMake(210.0, 210.0)]; UIImage *bigImage = [UtilMethod imageWithImageSimple:image scaledToSize:CGSizeMake(440.0, 440.0)]; [theImage retain]; [self saveImage:theImage WithName:@"salesImageSmall.jpg"]; [self saveImage:midImage WithName:@"salesImageMid.jpg"]; [self saveImage:bigImage WithName:@"salesImageBig.jpg"]; [self dismissModalViewControllerAnimated:YES]; [self refreshData]; [picker release]; } |
代码如下 | 复制代码 |
//压缩图片 + (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize { // Create a graphics image context UIGraphicsBeginImageContext(newSize); // Tell the old image to draw in this new context, with the desired // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage; } |
代码如下 | 复制代码 |
#pragma mark 保存图片到document - (void)saveImage:(UIImage *)tempImage WithName:(NSString *)imageName { NSData* imageData = UIImagePNGRepresentation(tempImage); NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* documentsDirectory = [paths objectAtIndex:0]; // Now we get the full path to the file NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName]; // and then we write it out [imageData writeToFile:fullPathToFile atomically:NO]; } |
代码如下 | 复制代码 |
#pragma mark 从文档目录下获取Documents路径 - (NSString *)documentFolderPath { return [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; } |
代码如下 | 复制代码 |
- (void)upLoadSalesBigImage:(NSString *)bigImage MidImage:(NSString *)midImage SmallImage:(NSString *)smallImage { NSURL *url = [NSURL URLWithString:UPLOAD_SERVER_URL]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:@"photo" forKey:@"type"]; [request setFile:bigImage forKey:@"file_pic_big"]; [request buildPostBody]; [request setDelegate:self]; [request setTimeOutSeconds:TIME_OUT_SECONDS]; [request startAsynchronous]; } |
标签:
原文地址:http://www.cnblogs.com/worldtraveler/p/4747101.html