简体   繁体   English

iPhone:如何更改相机的照片质量

[英]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.

相关问题 iPhone相机拍摄的图像质量 - Image quality taken by iPhone camera 如何找到iPhone相机照片的尺寸,如何调整尺寸? - How to find the size of iphone camera photo and how can I resize it? iPhone:如何通过iPhone照片应用程序等“编辑”功能从照片库或相机中获取图像 - iPhone:How to fetch image from photo library or camera with “edit” funcitionality like iPhone photo app 要从相机iPhone发送照片吗? - Send a photo from camera iPhone? 如何检测照片库中的图像是由iPhone相机拍摄还是导入 - how to detect if image from photo library was taken by iPhone camera or imported iPhone SDK-如何在UINavigationController中显示用相机拍摄的照片? - iPhone SDK - How to display a photo taken with the camera inside a UINavigationController? 如何在iPhone设备的照片库中保存从相机捕获的图像? - How to save Capture image from camera in IPhone device Photo Library? iPhone如何在相机应用程序中获得照片拍摄效果? - iPhone How to get photo taken effect like in camera application? 如何编辑直接从相机拍摄的照片并将其上传到 iphone? - How to edit photo directly taken from camera and upload it on iphone? 后部iPhone 4相机UIImageView的质量太高了? - Rear iPhone 4 camera too high quality for UIImageView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM