Я использую камеру в приложении iOS типа факса, и в этом случае изображение имеет тенденцию становиться огромным по размеру и вызывает явные задержки в работе веб-службы факса.Я не женат на лучшем качестве изображения.У меня вопрос: как уменьшить разрешение / уменьшить размер файла, чтобы он мог стать изображением меньшего размера?
#import <UIKit/UIKit.h>
//Definition of the delegate's interface
@protocol SnapShotViewControllerDelegate
-(void)selectedFileName:(NSString*)filename;
@end
@interface SnapShotViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate> {
IBOutlet UIButton *button;
IBOutlet UIImageView *image;
UIImagePickerController *imgPicker;
}
- (IBAction)grabImage;
- (IBAction)useImage;
@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (nonatomic,retain)UIImageView *image;
@property (nonatomic,retain)UIButton *button;
@property (nonatomic, assign) id<SnapShotViewControllerDelegate> delegate;
@end
#import "SnapShotViewController.h"
#import "PDFImageConverter.h"
@implementation SnapShotViewController
@synthesize imgPicker, image, button;
@synthesize delegate=_delegate;
- (IBAction)grabImage{
[self presentModalViewController:self.imgPicker animated:YES];
}
- (IBAction)useImage{
if ([image image]==nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Image Found" message:@"Click 'Grab Image' to take a snapshot first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else {
//do something with file
[self.delegate selectedFileName: filename];
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
[image setImage:img];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
if (imgPicker == nil) {
self.imgPicker = [[[UIImagePickerController alloc] init] autorelease];
}
//self.imgPicker.allowsImageEditing = YES;
imgPicker.delegate =self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.image = nil;
self.button = nil;
}
- (void)dealloc {
[imgPicker release];
[image release];
[button release];
[super dealloc];
}
@end