[英]iPhone: How to change camera photo quality
I've not found a answer to this question anywhere, but this seems like a typical problem: I am taking pictures from an iPhone 4, and I have to send these pics to a server through a POST-Request, but the server does not accept pictures that are bigger than 0,5 MB, so I have to compress the pictures before I send them. 我在任何地方都找不到这个问题的答案,但这似乎是一个典型的问题:我正在从iPhone 4拍照,我必须通过POST-Request将这些照片发送到服务器,但是服务器没有接受大于0.5 MB的图片,因此我必须先压缩图片,然后再发送。 In order to achieve this, I am calling following method: "NSData *imageData = UIImageJPEGRepresentation(tempImage, 0.7);", which means: I am compriming the image data, and it takes a lot of time (about 10s / pic). 为了实现此目的,我调用了以下方法:“ NSData * imageData = UIImageJPEGRepresentation(tempImage,0.7);”,这意味着:我正在压缩图像数据,这需要很多时间(大约10s / pic)。
Is there any way to control the quality of the camera device in order to take low quality pictures? 有什么方法可以控制相机设备的质量以拍摄低质量的照片?
Thanks in advance for helping. 在此先感谢您的帮助。
Anything that will block the main thread should be done in a background thread, including converting an image to a JPEG. 任何会阻塞主线程的操作都应在后台线程中完成,包括将图像转换为JPEG。 So you should start the JPEG conversion using performSelectorInBackground:withObject: and, when the conversion is done, pass the resulting NSData object back to the main thread. 因此,您应该使用performSelectorInBackground:withObject:开始JPEG转换,并在转换完成后将生成的NSData对象传递回主线程。
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
[self performSelectorInBackground:@selector(encodePhotoInBackground:) withObject:image];
}
- (void)encodePhotoInBackground:(UIImage*)image {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *imageData = UIImageJPEGRepresentation(image, 0.60);
[self performSelectorOnMainThread:@selector(saveImageData:) withObject:imageData waitUntilDone:NO];
[pool release];
}
- (void)saveImageData:(NSData*)imageData {
// Do something with the image
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.