.

Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

Image Cropping Application Source Code For Ios


Download Code Link is at the end of the post.


BJ Image Cropper:

BJ Image Cropper is very simple UIVIEW perhaps user friendly that allows user to do cropping, using a cropper which is displayed over an image, and you can drag cropper over image areas and can crop.For this you will need already build .h and .m file which i will provide including whole application. You can get this application by reading above note.

Reference Link

How this application Works ? :

  • When this application start running you will need to select a photo from camera roll and then image is loaded into the UIIMAGEVIEW.
  • After this You will need to press the button Crop when you Touch, a cropper will appear on subview of image and then you have to select your cropping area by touching the ends of rectangle appearing in that Subview.
  • After this You have to touch another button which takes crop image into a Dummy Variable of type UIIMAGE and then you have to put that Dummy variable into the UIIMAGEVIEW.

The Reason for explaining this non-technical part is to let people understand the flow of the program.

Now Again.


Touch Select button => Image loaded into UIIMAGEVIEW

Touch Crop button => Image from UIIMAGEVIEW is loaded into UIVIEW and a Cropper is appeared on that UIVIEW which is able to drag.

Touch Apply Crop Button => Cropped Image from the UIVIEW is Loaded into UIIMAGE *Image and then into UIIMAGEVIEW = image ;

Now here Comes the Code:


  •  This is update is Used to update the gui mask or rectangle which is on UIVIEW.
  • Size of this Rectangle can also be changed by holding clicks at the ends of rectangle corners.
  • In this function if origin is changed then a new origin with same height and width is update
  • If height and width is changed then a new height and width is update.
  • Both above task can be done simultaneously.
  • This function uses BJIMAGECropper.h and BjimageCropper.m which will be provided if you need just comment.
UIVIEW





- (void)updateDisplay {
self.boundsText.text = [NSString stringWithFormat:@"(%f, %f) (%f, %f)", CGOriginX(self.imageCropper.crop), CGOriginY(self.imageCropper.crop), CGWidth(self.imageCropper.crop), CGHeight(self.imageCropper.crop)];

if (SHOW_PREVIEW) {
self.preview.image = [self.imageCropper getCroppedImage];
self.preview.frame = CGRectMake(10,10,self.imageCropper.crop.size.width * 0.1, self.imageCropper.crop.size.height * 0.1);
}
}



- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([object isEqual:self.imageCropper] && [keyPath isEqualToString:@"crop"]) {
[self updateDisplay];
}
}

-(void) viewWillAppear:(BOOL)animated{
// No need to storeĆ¢€¦ this is 1 use only anyway. Save memory, and release it when done.
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;

}
  • This function crops the image this function takes coordinates of mask or rectangle from gui and subtract all pixels from that location to end corners.
Crop

-(IBAction)getcorp:(id)sender{

initWithFrame:CGRectMake(10,10,self.imageCropper.crop.size.width * 0.1, self.imageCropper.crop.size.height * 0.1)];
UIImage *im = [self.imageCropper getCroppedImage];
self.image_view.image = im;
for(UIView *sub in [self.view subviews])
{
if([sub isKindOfClass:[imageCropper class]])
[sub removeFromSuperview];
}
}

  •  This function creates a subview and extract image from UIImageView and creates a mask or rect on that image which is displayed on UIVIEW.
  • Means it creates a cropper on that gui UIVIEW where you image is displayed.
Subview


-(IBAction)corp:(id)sender{

CGFloat height = image_view.bounds.size.height;
CGFloat width = image_view.bounds.size.width;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tactile_noise.png"]];

self.imageCropper = [[BJImageCropper alloc] initWithImage:img andMaxSize:CGSizeMake(height,width) ];
[self.view addSubview:self.imageCropper];
self.imageCropper.center = self.view.center;
self.imageCropper.imageView.layer.shadowColor = [[UIColor blackColor] CGColor];
self.imageCropper.imageView.layer.shadowRadius = 3.0f;
self.imageCropper.imageView.layer.shadowOpacity = 0.8f;
self.imageCropper.imageView.layer.shadowOffset = CGSizeMake(1, 1);

[self.imageCropper addObserver:self forKeyPath:@"crop" options:NSKeyValueObservingOptionNew context:nil];

if (SHOW_PREVIEW) {
self.preview = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,self.imageCropper.crop.size.width * 0.1, self.imageCropper.crop.size.height * 0.1)];
self.preview.image = [self.imageCropper getCroppedImage];
self.preview.clipsToBounds = YES;
self.preview.layer.borderColor = [[UIColor whiteColor] CGColor];
self.preview.layer.borderWidth = 2.0;
[self.view addSubview:self.preview];
}

}
  • This function accesses camera roll.
Camera Roll

-(IBAction)next:(id)sender{

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:self.imgPicker animated:YES];
}
  • When Image is picked picker should be dismissed.

-(void)imagePickerControllerDidCancel :( UIImagePickerController *)picker{
[picker dismissModalViewControllerAnimated:YES];
}
  • Picks image from from camera roll.


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

self.image_view.image=img;

}



  • This the variable mask which is created on that gui UIView. 

- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

CGImageRef maskRef = maskImage.CGImage;

CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);

CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];
}

- (void)viewDidUnload
{
[super viewDidUnload];
[self setImageCropper:nil]; //image croper
[self setBoundsText:nil]; // image croper
[self.imgPicker release]; // Release this here, this will execute when modal view is popped.

}



- (void)viewDidUnload
{
[super viewDidUnload];
[self setImageCropper:nil]; //image croper
[self setBoundsText:nil]; // image croper
[self.imgPicker release]; // Release this here, this will execute when modal view is popped.
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Download Link: 




Text To Speech Conversion Using Espeak Engine For Iphone Application Development


Introduction:

There are some 3rd party libraries and API which are used to convert TTS ( TEXT TO SPEECH ) in iphone

1) Sphinix                        ( Not Efficeint )

2) Open-Ear                    ( Do not Required Internet Connectivity offline  TTS )

3) Google TTS                 ( Requires Internet Connection )

4) Acapela                      (Not Free You Have to pay to get SDK)

5) Objectuve C Speech Synthesizer Speak Engine  (Do Not Required Internet Connectivity One of the Good offline TTS )



What Is Open-Ear ?

Open-Ear is a shared and open source iOS frame Work for iphone text to speech conversion (TTS Synthesis).This Technology is used to convert English Text Into Speech for iphone .

What is the best part in Open-Ear ?

This source is best because thereĆ¢€™s no connectivity issue all processing takes place locally in the device mean you donĆ¢€™t needĆ¢€™s to connect to the internet.

Key Basic Concepts and Tips:

1 ) FliteController creates synthesized speech text to speech (TTS).

Now what is Flite Controller ?

Its an class which controls speech Sysnthesis that is text to speech in Open-Ears.

Recommended not to use Open-Ear?

Becuase app using Open-Ear library had not reached to Apple Store yet. Espeak Engine (Text to Speech Combing Its functionality with iOS Av Foundation Frame Work)

 Friends my focus is on Espeak Synthesized speech.

Now What is Espeak Engine ?

Espeak Engine is a Synthesized speech library which allows conversion of text into speech on iOS Device Just Like on Iphone.

Espeak Engine is static library of Objective-C  which is an OPEN SOURCE Synthesizer.

NOTE: Espeak has not been ported to iOS officially and Google has integrated some aspects like Google voice and translated for iPhone and iPad Apps.

Features (Espeak ):

NOTE: You have to study and understand the code to implement all this i will provide you just initial and basic code which will speak text.If you want to use and get application source code just comment and enter your email address i will mail you the whole project of TTS ( For Iphone Xcode Latest Compiler)

  • Good Quality Sound and Many Voices are Available like male or female voice.
  • This Is Written in C-Language so its very easy to understand.
  • Espeak Support many Human Languages.
  • You can Change speed of voices by changing inside code.
  • You can also enable or disable voice pronunciation .
  • Copy and Paste text anywhere in application.
  • You can also open mulitiple windows.

Sample Code:
I am Pasting here sample small part of code to get introduced to it.

I will Explain the main basic code

First what you have to do is import libraries that is header file.

#import Ć¢€œEspeakEngine.hĆ¢€

Now in main a  method is viewDidLoad.Here what you have to do is


  • Create a New Instance of speak engine
  • And Set All parameter u like to add like speed,volume,genderĆ¢€™s voice weather its male or female depends at you and etc other parameters.

-(Void viewDidLoad)

{[super viewDidLoad];

engine = [[ESpeakEngine alloc] init];

engine.volume=2;

engine setLanguage :@Ć¢€enĆ¢€;

}

Now What Happens when you write text in a text box and press speak button.Following Code is Executed now whats happening here.


  •  Here SpeakEngine method is call and a string is passed which is written in text box

-(IBAction)speech

{

NSString *text = self.textView.text;

[engine speak:text];

}

Now this main function call functions from implementation .m file and and header .h file contains definition,variables of that fuction

Download Code Link 


Post Source: http://crunchmodo.com/text-to-speech/