I am using the camera in a fax type iOS application in which case the image tends to get huge in size and causes apparent delays in faxing web service. I am not married to a better image quality. My question is how do I reduce resolution/reduce file size so that it can become a smaller file sized image?
#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
I forget where I saw this code (maybe here on SO)I got this code from this thread and I use it in one of my apps after I get an image from my iPhone camera: