Hallo liebe Forummitglieder,
bei meiner App mache ich ein Foto, das dann später per E-Mail versendet wird.
Dies musste ich kompremieren, jedoch kommt jetzt jedes Bild im 640 x 480 Format an.
Ich brauche aber 800 x 600
Hier mein Code:
Das Bild vom UIImagePickerController holen:
Die Eigentliche konvertierung ins kleinere Format:
Zugriff auf das Bild um es per E-Mail zu verschicken:
Danke im Voraus für eure Antworten.
Grüße Mario
bei meiner App mache ich ein Foto, das dann später per E-Mail versendet wird.
Dies musste ich kompremieren, jedoch kommt jetzt jedes Bild im 640 x 480 Format an.
Ich brauche aber 800 x 600
Hier mein Code:
Das Bild vom UIImagePickerController holen:
Die Eigentliche konvertierung ins kleinere Format:
Quellcode
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *directoryPath = [paths objectAtIndex:0];
- NSString *imageFile = [[NSString alloc] init];
- imageFile = [directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_01.jpg", artikel.text]];
- UIGraphicsBeginImageContext(CGSizeMake(800, 600));
- [image drawInRect: CGRectMake(0, 0, 800, 600)];
- UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
Zugriff auf das Bild um es per E-Mail zu verschicken:
Quellcode
- UIImage *myImage1 = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Documents/%@_01.jpg",NSHomeDirectory(), artikel.text]];
- NSLog(@"%@", [NSString stringWithFormat:@"%@/Documents/%@_01",NSHomeDirectory(), artikel.text]);
- NSData *imageData1 = UIImagePNGRepresentation(myImage1);
- [controller addAttachmentData:imageData1 mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@_01.jpg",artikel.text]];
- [UIImageJPEGRepresentation(smallImage, 1.0) writeToFile:imageFile options:NSAtomicWrite error:nil];
Danke im Voraus für eure Antworten.
Grüße Mario