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.
Related
im using the sdwebImage library to download images in tableview cell and display them.
the images are high resolution images. when the app launches, and starts loading, it suddenly crashes, without giving any errors, except sometime giving "received memory warning", and then the app crashes, its running on the simulator normally, but on an ipad, it is crashing,
the code where im putting the image in the cell:
- (void)setCellWithImage:(NSString *)imageURL
{
if (imageURL && [imageURL length]) {
[self.testingImageView sd_setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:#"ic_launcher"]];
}
}
any idea how to solve this issue?
I will suggest you to show in tableview use low quality image.
Get two image paths one for low quality image and another for high quality image. Show low quality image in Tableview and on click of particular image show high quality image.
There is only difference between simulator and phone is, Simulator doesnt have memory so on simulator this issue will not replicate.
I am developing an universal app where I have given a background image for a UIView using the following code.
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"backImage.png"];
[self.view addSubview:imgView];
[self.view sendSubviewToBack:imgView];
I have created the following images and added to the project,
backImage.png
backImage#2x.png
backImage-Portrait~ipad.png
backImage-Portrait#2x~ipad.png
backImage-Landscape~ipad.png
backImage-Landscape#2x~ipad.png
But it does not seem to take the correct images.
It works fine when I run the app on iphone (I mean it takes the backImage.png and backImage#2x.png accordingly) but when I run the app on ipad it does not use the ipad images, it still uses the iphone images.
Can anyone please tell what must be going wrong.
Thanks in advance.
You need to detect in your code what type of device is being used, and depending on that, choose the appropriate image.
See here: iOS detect if user is on an iPad
I may be wrong, but I don’t think UIImage will know whether to load the ‘portrait' or ‘landscape' version of an image, much less change them dynamically when you rotate your interface. I think you’re expecting a lot more magic then there is.
Those conventions work in the app launch snapshot, but I think that’s the extent of it?
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to efficiently show many Images? (iPhone programming)
I have hundreds of images, which are frame images of one animation (24 images per second). Each image size is 1024x690.
My problem is, I need to make smooth animation iterating each image frame in UIImageView.
I know I can use animationImages of UIImageView. But it crashes, because of memory problem.
Also, I can use imageView.image = [UIImage imageNamed:#""] that would cache each image, so that the next repeat animation will be smooth. But, caching a lot of images crashed app.
Now I use imageView.image = [UIImage imageWithContentsOfFile:#""], which does not crash app, but doesn't make animation so smooth.
Maybe there is a better way to make good animation of frame images?
Maybe I need to make some preparations, in order to somehow achieve better result. I need your advices. Thank you!
You could try caching say 10 images at a time in memory (you may have to play around with the correct limit -- i doubt it's 10). Everytime you change the image of the imageView you could do something like this:
// remove the image that is currently displayed from the cache
[images removeObjectAtIndex:0];
// set the image to the next image in the cache
imageView.image = [images objectAtIndex:0];
// add a new image to the end of the FIFO
[images addObject:[UIImage imageNamed:#"10thImage.png"]];
You can find your answer here: How to efficiently show many Images? (iPhone programming)
To summarize what is said in that link, you get better performance when showing many images if you use low level API's like Core Animation and OpenGL, as oppose to UIKit.
You could create a buffer of several images using an array. This buffer array of images can be loaded/populated using imageWithContentsOfFile from a background thread (a concurrent GCD asynchronous, for example).
How to save UIWebView Content into photo Library
-(IBAction)save:(id)sender{
UIImage* image = nil;
UIGraphicsBeginImageContext(webView.frame.size);
{
image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
if (image != nil) {
UIImageWriteToSavedPhotosAlbum(image,self, nil, nil);
}
}
This code is saving empty page.
I've released an app (Web2Pic) doing that, and please trust me that UIGraphicsBeginImageContext(webView.frame.size);
can do nothing except getting a small image from the visible area in our UIWebView ;-(
The right way is a bit complex but it just works:
1.Use JavaScript in our UIWebView to get these float values:
//Whole page size in HTML coordinate
document.body.scrollWidth
document.body.scrollHeight
//UIWebView visible size in HTML coordinate
window.innerWidth
window.innerHeight
2.Now we can 'cut' the whole page into dozens of UIWebView-sized small pieces. Then we can capture every small pieces individually and save them into our Cache. I implemented this by calculating page-offsets and use UIGraphicsBeginImageContext(webView.frame.size); to get a array of images. In addition, you should cache the image array into the file system, or the app will eventually crash!
3.When we finally got all the small pieces, we can start a full-resolution context: UIGraphicsBeginImageContext(CGSizeMake(document.body.scrollWidth,document.body.scrollHeight));
4.Render every small images into the big context based on the coordinates. And be careful to the corners, the last image in every line/row may not be a full image.
5.There is still one step left: saving the big image. Do not save it into the PhotoAlbum, because iOS will automatically cut down the resolution of images in the album. Instead, we can save it into the file system and enable the app's iTunes File Share support, or even write a simple in-app photo manager.
Hope these can help ;-)
Yichao Peak Ji