uiimagejpegrepresentation

iOS UIImageJPEGRepresentation error: Not a JPEG file: starts with 0xff 0xd9

做~自己de王妃 提交于 2019-11-28 10:00:21
I am writing a .jpg file to my app's Documents directory like this: NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0); BOOL retValue = [img writeToFile:myFilePath atomically:YES]; Later, I load that image back into a UIImage using: UIImage *myImage = [UIImage imageWithContentsOfFile:path]; I know it works because I can draw the image in a table cell and it is fine. Now if I try to use UIImageJPEGRepresentation(myImage, 1.0), the debugger prints out these lines: <Error>: Not a JPEG file: starts with 0xff 0xd9 <Error>: Application transferred too few scanlines And the function returns nil.

UIImageJPEGRepresentation received memory warning

时光毁灭记忆、已成空白 提交于 2019-11-27 14:32:33
I receive a memory warning when using UIImageJPEGRepresentation, is there any way to avoid this? It doesn't crash the app but I'd like to avoid it if possible. It does intermittently not run the [[UIApplication sharedApplication] openURL:url]; - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; NSData *imageToUpload = UIImageJPEGRepresentation(image, 1.0); // code that sends the image to a web service (omitted) // on success from the service // this

Using ALAssetsLibrary and ALAsset take out Image as NSData

痞子三分冷 提交于 2019-11-27 10:11:04
问题 I wish to extract the image using ALAssetsLibrary and ALAsset directly in the form of a NSData object. Using a NSURL I take out the image in the following manner. NSURL *referenceURL =newURL; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library assetForURL:referenceURL resultBlock:^(ALAsset *asset) { UIImage *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; } Now here we take the image as a UIImage, but I need to take the

image compression by size - iPhone SDK

依然范特西╮ 提交于 2019-11-27 06:16:43
I would like to compress images (camera/photo library) and then send it to the server. I know I can compress by height and width, but I would like to compress the images by size to a fixed size (200 KB) only and keep the original height and width. The scale factor in JPEGRepresentation does not represent the size and only compression quality. How can I achieve this (compress to a fixed size) without using any third party library? Thanks for any help. Heres some example code that will attempt to compress an image for you so that it doesn't exceed either a max compression or maximum file size

iOS UIImageJPEGRepresentation error: Not a JPEG file: starts with 0xff 0xd9

99封情书 提交于 2019-11-27 03:20:57
问题 I am writing a .jpg file to my app's Documents directory like this: NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0); BOOL retValue = [img writeToFile:myFilePath atomically:YES]; Later, I load that image back into a UIImage using: UIImage *myImage = [UIImage imageWithContentsOfFile:path]; I know it works because I can draw the image in a table cell and it is fine. Now if I try to use UIImageJPEGRepresentation(myImage, 1.0), the debugger prints out these lines: <Error>: Not a JPEG file:

PNG/JPEG representation from CIImage always returns nil

左心房为你撑大大i 提交于 2019-11-26 17:59:21
I'm currently making a photo editing app. When a photo is selected by the user, it is automatically converted into black and white using this code: func blackWhiteImage(image: UIImage) -> Data { print("Starting black & white") let orgImg = CIImage(image: image) let bnwImg = orgImg?.applyingFilter("CIColorControls", withInputParameters: [kCIInputSaturationKey:0.0]) let outputImage = UIImage(ciImage: bnwImg!) print("Black & white complete") return UIImagePNGRepresentation(outputImage)! } The problem I am having with this code is that I keep getting this error: fatal error: unexpectedly found nil

UIImageJPEGRepresentation received memory warning

倖福魔咒の 提交于 2019-11-26 16:47:49
问题 I receive a memory warning when using UIImageJPEGRepresentation, is there any way to avoid this? It doesn't crash the app but I'd like to avoid it if possible. It does intermittently not run the [[UIApplication sharedApplication] openURL:url]; - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; NSData *imageToUpload = UIImageJPEGRepresentation(image, 1.0);

How to zoom in/out an UIImage object when user pinches screen?

被刻印的时光 ゝ 提交于 2019-11-26 12:03:34
I would like to zoom in/out an UIImage object when the user performs the standard pinch action on my application. I'm currently using a UIImageView to display my image, if that detail helps in any way. I'm trying to figure out how to do this, but no such luck so far. Any clues? Brad Larson Another easy way to do this is to place your UIImageView within a UIScrollView . As I describe here , you need to set the scroll view's contentSize to be the same as your UIImageView's size. Set your controller instance to be the delegate of the scroll view and implement the viewForZoomingInScrollView: and

image compression by size - iPhone SDK

我怕爱的太早我们不能终老 提交于 2019-11-26 11:56:10
问题 I would like to compress images (camera/photo library) and then send it to the server. I know I can compress by height and width, but I would like to compress the images by size to a fixed size (200 KB) only and keep the original height and width. The scale factor in JPEGRepresentation does not represent the size and only compression quality. How can I achieve this (compress to a fixed size) without using any third party library? Thanks for any help. 回答1: Heres some example code that will

How to zoom in/out an UIImage object when user pinches screen?

醉酒当歌 提交于 2019-11-26 03:35:02
问题 I would like to zoom in/out an UIImage object when the user performs the standard pinch action on my application. I\'m currently using a UIImageView to display my image, if that detail helps in any way. I\'m trying to figure out how to do this, but no such luck so far. Any clues? 回答1: Another easy way to do this is to place your UIImageView within a UIScrollView . As I describe here, you need to set the scroll view's contentSize to be the same as your UIImageView's size. Set your controller