iphone photo maximum size - iphone

i want to know there a limitation in size for an iphone to display an image? as the resolution of iphone is 320*480 px. i am developing an app which fetches photos from an URL and that URL contains some photos os size > 600KB.So when i launch the app in simulator it behaves properly but in device the application crashes as soon as photos with higher resolution are displayed , and when lower resolution photos are displayed the app does not crash in the device.

From Apple's doc:
You should avoid creating UIImage objects that are greater than 1024 x 1024 in size. Besides the large amount of memory such an image would consume, you may run into problems when using the image as a texture in OpenGL ES or when drawing the image to a view or layer. This size restriction does not apply if you are performing code-based manipulations, such as resizing an image larger than 1024 x 1024 pixels by drawing it to a bitmap-backed graphics context. In fact, you may need to resize an image in this manner (or break it into several smaller images) in order to draw it to one of your views.

Related

Reducing iOS app size - Are <imagename>#2x.png images redundant?

I am trying to reduce the size (30+ MB) of my binary submission, and I sense that images acquire a sizable (>26 MB) part.
I also observed that if I remove retina images (#2x.png), iOS gracefully replaces them with 4-inch retina (-568h#2x.png) versions.
Are the retina images really redundant if I supply -568h#2x.png versions?
P.S.
Not that one image makes much of a difference, but if the answer is a Yes, does this also apply for default.png?
#2x images are for retina devices. They look much crisper and clean on retina devices (e.g. iPad3, iPhone 5) as compared to their non-retina counterpart images. Here are few suggestions to reduce size of your binary.
1) For background images check if they are really needed. If they are simple solid color images you can simply set the backgroundColor of the UIView.
2) Whenever possible use 9 patch (also called 9 scale) images for button or view backgrounds. They are generally 1 px wide images and you can use below method of UIImage to use them
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
In general image#2x can be used as a stand in for image, but not the other way around (because they wouldn't look good). The side effect of doing this is that more memory will be used and on non-retina devices that could cause a problem. If you aren't supporting non-retina devices then you don't need any images.
Generally speaking you shouldn't have many image-568h#2x images other than the Default and other background images. Most of your content images will be the same size no matter what the screen size is. You do not need differently named images for a button of the same size on multiple different screen sizes.

How to create big image when we have small image in iOS without pixel distortion?

I am working on an app which is fully dependent on images. I have images like 320*480 now I want those same images with 768*1024 dimension. I can get it by UI designer and place in my bundle but my application is for universal app so I needed to include same image for iPhone retina, iPad, iPad retina. If I am using multiple images my IPA size goes increase (ex: if an image with 320*480 having 200KB now if I again adding 768*1024 the size of my IPA will increased to at least 200KB).
Idea: I am placing only 320*480 images and planning to create 768*1024 images programmatically which means only one set of images I am using in my bundle.
Work done: By looking some blogs I found that using below code we can create required image sizes.
- (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
UIImage *smallImage=[UIImage imageNamed:#"1.png"];
UIImage *bigImage=[self scale:smallImage toSize:CGSizeMake(768, 1024)];
[UIImageJPEGRepresentation(bigImage,2.0) writeToFile:[[self applicationDocumentsDirectory]stringByAppendingPathComponent:#"upload.png"] atomically:YES];
Problem: Above code works cool and getting the expected size of images but only problem is I am getting pixel distortion on the end image.
Question:
Is there any good or efficient solution to get different dimensions with out distortion image from the small image or I need to get all my images from the UI designer. If we have normal Image can we create same image for retina display?
Is there a better solution?
It is impossible to create a larger image from a smaller image without distortion or pixelation. There is no way to magically fill in the additional detail.
The real world doesn't work like TV or movies where people zoom in on images and magically get a lot of detail. :)
If you feel that your app is too big when you include 5 sets of images for:
iPhone 3.5" non-retina
iPhone 3.5" retina
iPhone 4" retina
iPad non-retina
iPad retina
then you have a few options:
Make two apps. One for iPhones and iPod touches, and one for iPads.
Ship your app with only a small subset of images. Then when the app is run the 1st time, the app can download only the images required for the current device.
Only include the largest images. As the app needs each image, it can create a properly sized version of the image and use that. Each conversion would only need to be done once per image. Downsizing an image gives much better results than trying to upscale.
You can resize image programmatically but they will not look good. I wouldn't worry that much about bundle size. Just put native-resolution image for all devices and forget about resizing.
If you want, you can crop and scale down from the big images, but if you are scaling up, there will be quality loss because the file does not contain enough information for all of those pixels. I would suggest either:
1) The easiest method is to make a bunch of different versions of the image. (see rmaddy's answer).
2) If you really don't want multiple images, take the largest one and scale downwards. Since they have different aspect ratios, simply scaling will cause some distortion; you will need to crop as well.
Either way, you will need to open up your image editor and make a larger image.

Use only retina images in cocos2d

I am using 2 images: image.png and image-hd.png and it works fine for retina and non-retina too.
But what I want to do now is to remove all non-retina images and leave only retina images. I heard that a non-retina device will scale the image down itself. I tried it but it didn't work :( How I do this? What name should I give to the image that it will show picture its actually size on retina and for non-retina will be scaled down?
No, Retina images are not scaled down automatically.
Only using Retina images and using them scaled down on standard resolution display devices is a bad idea.
Non-Retina devices have far less memory than Retina devices, but you're forcing them to load the Retina resolution images. In other words: device has half the memory, but is forced to load images that consume four times as much texture memory as need be.
Non-Retina devices have slower GPU & CPU. But you're forcing them to work on four times the number of pixels. Performance suffers.
You probably need to scale it down manually. I'm not sure if thats the best idea.
But I think you can just scale down the images to 0.5 if in retina device.
About images, its important to remember that each image is taking memory according to the size of the next power 2 dimensions. Which means that 20X20 pic will take the same memory as 32X32, and 130X260 will take 256X512.
So sometimes just handling your image sizes better or using something like Sprite Sheet.

iPhone memory warning for high resolution images

I have an app which display images in full Screen. Some of the images are 1952x3680 pixels and these images are raising memory warning level=1 and level=2.
How should i handle these image?
Scale your images down considerably. There is absolutely no reason you need images at that resolution in an iPhone app.
Don't use them. Either get your server to deliver a thumbnail version of the image (maybe using a thumb.php/jsp/asp/... file with GET params x=<width>&y=<height>), or scale the image down on the iPhone and discard the original data. The former method is vastly preferred as it saves on both bandwidth and large memory allocations client-side.
The largest images you should be working with are 480x320 (iPhone 3GS and earlier) and 960x640 (iPhone 4).
EDIT: The other situation I didn't think of is if you're bundling these images with the app. Please, please don't do that. If you have images that big, scale them down in Apple's Preview or any image editor to the sizes noted, and ideally have two copies, image.png and image#2x.png which are shown depending on the scale of the device's screen.
The screen itself is only 320x460 (not considering the clock bar on top), and 640x960 for retina display. There is no reason to have images this large to begin with. Scale them down. It'll both prevent the memory warnings and stymie unnecessary image size.
As said before, scale it down if you only want to show the image without zooming in fullscreen.
If you need to zoom and show it detailed, google for CATiledLayer. There are good examples around.

How to handle loading multiple images for the purpose of scrolling and zooming? Does DPI of an image affects the way an iPad is going to load it?

I am currently working on an image gallery for iPad. As of now there are about 100 images and the count may increase further. The images I am using are of the resolution 2134x1602 # 300dpi. Now with ~2.5MB, i have lost the smoothness in scrolling the images to next image. Also I want to zoom the image up to 8X. The images I am using are all PNG type.
The app works fine in the simulator but crashes bad on the device. Instruments show no leaks and no bad allocations too. It must be some Internal memory issue for sure since the gdb reports memory warning while running on the device. I would like to tell you that I am lazily loading the images.
Can anyone help me with this issue and the strategy i should use to get rid of the slow loading and scrolling. Also I'll be glad if you let me know how an iPad's GPU processes the images it wants to load. Also i would like to cite that changing DPI didn't work out well.
Eagerly waiting for some help.
Thank You.
Your app is crashing because you are running out of memory.
What you will need to do is scale/tile the images. Have a look at how Google Maps works in a web browser on a normal PC, you will need to do something like this. The screen resolution on the iPad is 1024x768 pixels, so there's no point loading more than that amount of data at any one time. When displaying your image at > 0.5x scale, tile it into sections that are max 1024x1024, pre-scaled. Cache everything to disk. When displaying your image at < 0.5x scale, consider having thumbnails at different resolutions. In between different resolutions, do an alpha blend of two images of different scales: eg for scale 0.75x, do a 50% blend of four tiled scale 0.5x images and one scale 1.0x image.