title: How to decrease the size of the Image in objective c
body: <p>The problem is like, when the image size is more than 60 kb, it is not posting the image to the web service , but if the image size is less than 60 kb, its posting to the web service.</p>
  
  <p>How to decrease the size of the Image in objective c.
  The following is the code which i am using,</p>
  
  <pre><code>-(IBAction)sendEmail:(id)sender
  {
      AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  
      NSLog(@"TABLEDIC%@",appDelegate.tableDic);
      //Parsing
      recordResults = FALSE;
  
      NSString *soapMessage = [NSString stringWithFormat:@"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
                               "&lt;soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;\n"
                               "&lt;soap:Body&gt;\n"
                               "&lt;CreateTextMail xmlns=\"http://tempuri.org/\"&gt;\n"
                               "&lt;listid&gt;%@&lt;/listid&gt;\n"
                               "&lt;fromid&gt;%@&lt;/fromid&gt;\n"
                               "&lt;subject&gt;%@&lt;/subject&gt;\n"
                               "&lt;replyto&gt;%@&lt;/replyto&gt;\n"
                               "&lt;loginid&gt;%@&lt;/loginid&gt;\n"
                               "&lt;fromname&gt;%@&lt;/fromname&gt;\n"
                               "&lt;forward&gt;%@&lt;/forward&gt;\n"
                               "&lt;subscribe&gt;%@&lt;/subscribe&gt;\n"
                               "&lt;mailpriority&gt;%@&lt;/mailpriority&gt;\n"
                               "&lt;recievermailtext&gt;%@&lt;/recievermailtext&gt;\n"
                               "&lt;mailbody&gt;%@&lt;/mailbody&gt;\n"
                               "&lt;emailname&gt;%@&lt;/emailname&gt;\n"
                               "&lt;signature&gt;%@&lt;/signature&gt;\n"
                               "&lt;listname&gt;%@&lt;/listname&gt;\n"
                               "&lt;emailtype&gt;%@&lt;/emailtype&gt;\n"
                               "&lt;imagecontent&gt;%@&lt;/imagecontent&gt;\n"
                               "&lt;imagename&gt;%@&lt;/imagename&gt;"
                               "&lt;/CreateTextMail&gt;\n"
                               "&lt;/soap:Body&gt;\n"
                               "&lt;/soap:Envelope&gt;\n",[appDelegate.tableDic valueForKey:@"tableID"],[appDelegate.tableDic valueForKey:@"fromname"],[appDelegate.tableDic valueForKey:@"subject"],[appDelegate.tableDic valueForKey:@"replyto"],[appDelegate.tableDic valueForKey:@"loginid"],[appDelegate.tableDic valueForKey:@"fromname"],forward.text,subscribe.text,[appDelegate.tableDic valueForKey:@"mailpriority"],receivermailtext.text,body.text,[appDelegate.tableDic valueForKey:@"emailName"],[appDelegate.tableDic valueForKey:@"signature"],[appDelegate.tableDic valueForKey:@"tableName"],emailType,strEncoded,imageName.text
                               ];
  
      NSLog(@"SOPA%@",soapMessage);
  
      NSURL *url = [NSURL URLWithString:@"http://www.xxx.net/xxx/xxx.asmx"];
      NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
      NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
  
  
      [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
      [theRequest addValue:@"http://tempuri.org/CreateTextMail" forHTTPHeaderField:@"SOAPAction"];
      [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
      [theRequest setHTTPMethod:@"POST"];
      [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  
      NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  
      NSHTTPURLResponse *urlResponse = nil;
      NSError *error = [[NSError alloc] init];
      NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&amp;urlResponse error:&amp;error];
  
      NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
      NSLog(@"Response Code : %d",[urlResponse statusCode]);
      if([urlResponse statusCode] &gt;= 200 &amp;&amp; [urlResponse statusCode] &lt; 300)
      {
          NSLog(@"Response: %@",result);
      }
  
      if( theConnection )
      {
          webData = [NSMutableData data];
      }
      else
      {
          NSLog(@"theConnection is NULL");
      }
  
      [subject resignFirstResponder];
      [replyto resignFirstResponder];
      [loginid resignFirstResponder];
      [fromname resignFirstResponder];
      [emailName resignFirstResponder];
      [signature resignFirstResponder];
      [listName resignFirstResponder]; 
  
  
  
  }
  
  
  -(void)takeCamera
  {
      if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
      {
          NSLog(@"take a photo");
          UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
          imagePicker.delegate = (id)self;
          imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  
          imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
          imagePicker.allowsEditing = NO;
          [self presentModalViewController:imagePicker animated:YES];
  
          newMedia = YES;
      }
  }
  
  -(void)pickCameraRoll
  {
      if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
      {
          UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
          imagePicker.delegate = (id)self;
          imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
          imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
          imagePicker.allowsEditing = NO;
          [self presentModalViewController:imagePicker animated:YES];
          newMedia = NO;
      }
  }
  
  -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  {
      NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
      [self dismissModalViewControllerAnimated:YES];
      if([mediaType isEqualToString:(NSString *)kUTTypeImage])
      {
          UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
          imageView.image = image;
          NSData *myData = UIImagePNGRepresentation(image);
         // NSLog(@"NSData : %@",myData);
  
          [Base64 initialize];
          strEncoded = [Base64 encode:myData];
          NSLog(@"strEncoded : %@",strEncoded);
  
          if(newMedia)
              UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:finishedSavingWithError:contextInfo:), nil);
          NSLog(@"image pick");
      }
      else if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
      {
  
      }
  }
  
  -(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  {
      if(error)
      {
          UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Save Failed" message:@"Failed to save image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alert show];
      }
  }
  
  -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  {
      [self dismissModalViewControllerAnimated:YES];
  }
  </code></pre>
  
  <p>What would be the problem in the device,where it is failing to send the image to the web service, but able to send successfully in the iphone simulator.
  Any suggestions would be very helpful.
  Thanks in advance.</p>