UIImageJPEGRepresentation not working in iOS 13.2.3 - objective-c

I am using the following code to convert UIImage to NSData:
imgData = UIImageJPEGRepresentation(image, 0.75);
The code is working fine with iOS 12.4, but when I try with it with iOS 13.2.3, it returns nothing.
Any help would be greatly appreciated.
Thank you.

After thoroughly examining and researching, it turned out that UIImageJPEGRepresentation with 0.75 compression was causing a crash due to large image size. Changing 0.75 to 0.1 solved the problem.

Related

HTML font size manipulation on uiWebview is failing for latest iOS update

I have been using this function for ages and no problem was faced, on the latest iOS update it stopped working, on execution the font size doesn't change.
What could be the reason and how could it be fixed?
- (void)changeFontSize:(int)font {
NSLog(#"changeFontSize %i", font);
NSString *jsString = [NSString stringWithFormat:#"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'", font];
[readingWebView stringByEvaluatingJavaScriptFromString:jsString];}
After further testing I have noticed that this problem only occurs on iPad iOS 10.1.1, but it works correctly on iPhone 10.1.1.
Okey this is a known issue and has an open radar here , but is reported to be fixed in iOS 10.2 beta 1 and in iOS 10.2 beta 2, so you will just have to wait, or you can try some of the solutions proposed on the radar, like enabling text auto resizing like so
[[[webView.scrollView.subviews.firstObject webView] preferences] _setTextAutosizingEnabled:YES];
hope this helps !

My app getting Crash

I am creating app like , which will take photos and shows the taken photos in thumbnail as scrolling part below the camera view .it is taking photos.but if i take more than 30 pictures my app is getting crash .So i connect my iPod with Xcode and i run , .I don't why it happens .I think may be memory issue .because i am taking more pictures.If it is memory issue please tell me what i should do for that .please help me.
Try this code to Reduce the size of image
- (UIImage )imageWithImage:(UIImage )image convertToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
Classic memory issue; you are using memory quickly enough that your app and, likely, the debugging conduit are being killed by the system.
To fix? Use less memory. Or, 'ore specifically, release the full sized images as soon as you have thumbnails generated.

How get a High Performance UIWebView -> UIImage on ipad retina?

Have page flip type application that needs to convert the contents of a fullscreen UIWebView to a UIImage very quickly (e.g. 200ms tops). Sacrificing quality for speed is OK. Having a real tough time getting anywhere near this on a iPad3 retina.
Do create a UIImage i am doing the common renderInContext method:
UIGraphicsBeginImageContextWithOptions(frame.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
On a ipad3 retina display I typically see 400-500ms. Interestingly the second time the method is run it is much quicker (around 100ms), which doesn't help but suggests some sort of caching is happening.
I have tried the following things:
I have tried playing with the scale and opaque parameters UIGraphicsBeginImageContextWithOptions to ever possible combination. Setting the scale to say .5 or 1.0 actually makes it even slower.
Adding CGContextSetInterpolationQuality(context, kCGInterpolationNone). No change to performance.
webview.shouldRasterize=YES. No change to performance.
Shrinking the UIWebView in half and then scaling to fullscreen . This does help but is still around 300ms.
Any other ideas? Running this on a ipad1-2 is ok - but the ipad3 retina just kills the performance.

let user crop image in iOS

Is there a built in function in objective-c to do image cropping like the one in iOS photo gallery? I have tried enabling editing in UIImagePickerController, but it doesn't do the same. Thanks!
there are quite a few ways to crop images using the Core Graphics functions, the most basic one would be:
CGRect cropRect = CGRectMake(0, 0, 100, 100);
CGImageRef cropped_img = CGImageCreateWithImageInRect(yourUIImage.CGImage, cropRect)
This is no built in function. The way to do it would be to take the image an get a frame around the portion of the image you want.
This question should help you

-[NSString sizeWithFont:] returns different results in release and debug builds [duplicate]

This question already has answers here:
App Store code runs different from Xcode/Device code on iPhone 3G
(4 answers)
Closed 2 years ago.
I've used this code to resize a UILabel's frame height to fit dynamic text several times with success:
(...)
CGSize labelSize = [thelabel.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
All was well until I started to build my apps using the iOS5 SDK.
For armv6 devices (iPhone3G/-), when building for debug, the label size is okay, but when building for release, the height value retrieved is the same as the width. I am running both of these builds on an actual device.
example with following log line:
NSLog(#"labelSize: %f %f", labelSize.width, labelSize.height);
output:
iphone3G - debug >
Thu Nov 3 18:22:50 unknown appname[1071] : labelSize: 115.000000 19.000000
iphone3G - release >
Thu Nov 3 18:22:50 unknown appname[1071] : labelSize: 115.000000 115.000000
Can anyone help or provide me with another solution to adjusting UILabel's height based on the text length?
I'm aware there are some similar questions about this method, but they do not address this particular issue.
Had the same issue.
If you follow the link supplied by vfonseca, you arrive at: Is there a way to compile for ARM rather than Thumb in Xcode 4?
And the selected answer tells you how to add the correct compiler flags to prevent this. Alternatively upgrade to Xcode 4.3 which has fixed this bug.
I still haven't managed to understand the problem.
Although, replaced the UILabel resize method with an alternative way:
//init and store initial rect
CGRect initialLabelRect = CGRectMake(2*kMargin, auxHeight , 200, 0 /*will be overriden*/);
UILabel *dataLabel = [[UILabel alloc] initWithFrame:initialLabelRect];
dataLabel.text = #"long text here";
[dataLabel setFont:[UIFont fontWithName:#"Arial-BoldMT" size:15]];
//fit size will adjust both width and height, but i'll be discarding the width
[dataLabel sizeToFit];
//set the new frame (initial, but with the computed height)
dataLabel.frame = CGRectMake(initialLabelRect.origin.x, initialLabelRect.origin.y, initialLabelRect.size.width, dataLabel.frame.size.height);
//add and release
[superview addSubview:dataLabel];
[dataLabel release];
So, the issue persists, but, for the time being... I'm replacing the code occurrences for this approach.
If someone come up with a clue about what happened, please let me know. I'm guessing it+s a bug on sizeWithFont method... but is always easier to blame on the SDK when we can't understand... :)
Thank you all. Cheers.
I've discovered a difference in what sizeWithFont:constrainedToSize:lineBreakMode: will return depending on which architecture your code is running on. I've used the function to calculate the height of strings I want to display in UILabels in UITableViewCells so that I can calculate the final height of the cell. I was getting one size on my iPhone 4, and a tester was getting big large cells on their iPod (old armv6 device).
The solution was posted here: Is there a way to compile for ARM rather than Thumb in Xcode 4?
I'm sure the optimization fix described below works as well, but disabling thumb might allow you to maintain your optimization settings? I don't know, you'd have to test this.