Tuesday, September 21, 2010

Give the proper Resolution of Image as it have

/* // before wiout high resolutions
#define kScreencapTopX 15
#define kScreencapTopY 65
#define kScreencapHeight 335
#define kScreencapWidth 290

 */
//With high resolutions
#define kScreencapTopX 30
#define kScreencapTopY 130
#define kScreencapHeight 670
#define kScreencapWidth 580

-(UIImage *) imageProperResolutions{
CGRect rect =CGRectMake(0,0,320,480);
///UIGraphicsBeginImageContext(rect.size);
UIGraphicsBeginImageContextWithOptions(rect.size,NO,2.0);
[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGRect croppedFrame = CGRectMake(kScreencapTopX,kScreencapTopY,kScreencapWidth,kScreencapHeight);
CGImageRef finalCGImage;
finalCGImage= CGImageCreateWithImageInRect(image.CGImage, croppedFrame);//[self imageByCropping:image toRect:croppedFrame];
UIImage *finalImage =[UIImage imageWithCGImage:finalCGImage];
UIGraphicsEndImageContext();
//XXX memory managment?
return [finalImage retain];
}

Monday, September 6, 2010

add an UIImage in MailComposer Sheet of MFMailComposeViewController in iPhone


- (void)createEmail {
//Create a string with HTML formatting for the email body
    NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@""] retain];
 //Add some text to it however you want
    [emailBody appendString:@"Some email body text can go here
"];
 //Pick an image to insert
 //This example would come from the main bundle, but your source can be elsewhere
    UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
 //Convert the image into data
    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
 //Create a base64 string representation of the data using NSData+Base64
    NSString *base64String = [imageData base64EncodedString];
 //Add the encoded string to the emailBody string
 //Don't forget the "" tags are required, the "" tags are optional
    [emailBody appendString:[NSString stringWithFormat:@"

",base64String]];
 //You could repeat here with more text or images, otherwise
 //close the HTML formatting
    [emailBody appendString:@""];
    NSLog(@"%@",emailBody);

 //Create the mail composer window
    MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
    emailDialog.mailComposeDelegate = self;
    [emailDialog setSubject:@"My Inline Image Document"];
    [emailDialog setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:emailDialog animated:YES];
    [emailDialog release];
    [emailBody release];
}

http://stackoverflow.com/questions/1527351/how-to-add-an-uiimage-in-mailcomposer-sheet-of-mfmailcomposeviewcontroller-in-iph
or
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
//Setting up the Subject, recipients, and message body.
[mail setToRecipients:[NSArray arrayWithObjects:@"address@example.com",nil]];
[mail setSubject:@"iCostume"];
[mail setMessageBody:@"Your custom costume picture" isHTML:NO];
UIImage *pic = [self imageToShare];
NSData *exportData = UIImageJPEGRepresentation(pic ,1.0);
[mail addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Picture.jpeg"];
//Present the mail view controller
[self presentModalViewController:mail animated:YES];
}
//release the mail
[mail release];