Supporting both high-res and low-res images - iphone

What is the best pattern for displaying images both on iOS3 and iOS4?
For example, here's code for a custom activity animation:
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"s01"],
[UIImage imageNamed:#"s02"],
[UIImage imageNamed:#"s03"],
[UIImage imageNamed:#"s04"],
[UIImage imageNamed:#"s05"],
nil];
On low-res and high-res devices running iOS4, the images load as expected. On iOS3 the images cannot be found since the .png extension is seen as missing.
What's the right way to deal with this situation? Do I need to throw hacky conditionals throughout my code or is there a cleaner method?
Is something from Matt Gallagher's article a good approach?
http://cocoawithlove.com/2010/07/tips-tricks-for-conditional-ios3-ios32.html

You still get the auto '#2x' loading behavior in iOS4 even if you use the file extension, so [UIImage imageNamed:#"so1.png"] is fine (it will find "so1#2x.png" if you're running on a Retina Display with OS 4) plus it's backwards compatible with 3, where it will always find the low-res version of the file.

See the "Loading Images into Your Application" section here.

Related

jpg images are shown in iphone simulator but not in iPhone test device

i'm sorry for my english.
i'm new in iphone development and happens to me a strange things.
I have a set of jpg images to show in a table view. When i test the app in iphone simulator everything is ok and work properly but when built and run the same code in iphone test device the same images aren't displayed.
Another strange behavior is that with a set of png images instead of jpg are shown perfectly in simulator like as in iphone test device.
Anyone can suggest me a solution?
I detect the name of image to load from a json file. This is the code that i use to show the image:
UIImageView *immaginePiadina = [[UIImageView alloc] initWithFrame:immagineValueRect];
[immaginePiadina setImage:[UIImage imageNamed:[item objectForKey:#"immagine"]]];
where [item objectForKey:#"immagine"] is an element of my json file like this:
"nome": "66",
"immagine": "pianetapiadabufalavesuviani",
"prezzo": "€ 7,50",
"nomeingrediente": [
"bufala",
"vesuviani"
]
How you can see i refer to the image with only the name of the file and without the file extension. I did it in this way to show image retina, it's wrong?
I exclude that i wrote a different case sensitive name because the png set works properly.
thanks a lot!!
There are possibly two separate issues that need separation, here is how to solve your problem.
First write a method using the NSFileManager, that given a file path verifies a file exists and has a size greater than 0. Insert a call to this everywhere you fail to open an image. If you use "imageNamed" then get the path to the bundle and create the path. If this method fails to find an image, fix it.
Second, the image decoding is different for the simulator and the device - the simulator uses the full OSX libraries. So take one image that fails to open and move it somewhere. Open it in Preview and export it using the same name but with png+alpha format. Change your code to expect a png not a jpg, and retest. Make sure you still use the first method to insure the file is there.
Once you get one success you can try other options, like using Preview exported jpegs. The reason this should work is that all of these image formats permit a huge range of options all of which iOS does not support.
Given that the current format us the problem, you can script changes using the "sips" program, which is what Preview uses.
I solve my problem using the following code:
NSString* path = [[NSBundle mainBundle] pathForResource:[item objectForKey:#"immagine"] ofType:#"jpg"];
NSLog(#"%#",path);
UIImage* theImage = [[UIImage alloc] initWithContentsOfFile:path];
I don't know the reason but in this way i haven't any problem to display jpg in my iPhone test device. Maybe because NSBundle specify also the extension of the file.
Thanks #David-h that directed me in the right way to solve my problem.
Check the extensions of your images. If you write .PNG, in the simulator is Ok, but not in the device.

Make applications similar to Talking Tom Cat

I want to make an applications similar to Talking Tom Cat, Touch Pets Cats/, Virtual Monkey and the Tap Zoo.
I have knowledge of Iphone basic animation.
I want to know that can i make these apps without OpenGL ,cocos and other gaming environment...
Can i make it by using only basic frameworks...
Well if its related to talking tom then there is no OpenGLES Use... they are simply using images and animate them. using something like this -
aniImage = [[UIImageView alloc] init];
UIImage* opa1 = [UIImage imageNamed:#"o1.png"];
UIImage* opa2 = [UIImage imageNamed:#"o2.png"];
UIImage* opa3 = [UIImage imageNamed:#"o3.png"];
UIImage* opa4 = [UIImage imageNamed:#"o4.png"];
UIImage* opa5 = [UIImage imageNamed:#"o5.png"];
UIImage* opa6 = [UIImage imageNamed:#"o6.png"];
UIImage* opa7 = [UIImage imageNamed:#"o7.png"];
UIImage* opa8 = [UIImage imageNamed:#"o8.png"];
UIImage* opa9 = [UIImage imageNamed:#"o9.png"];
UIImage* opa10 = [UIImage imageNamed:#"o10.png"];
UIImage* opa11 = [UIImage imageNamed:#"o11.png"];
UIImage* opa12 = [UIImage imageNamed:#"o12.png"];
UIImage* opa13 = [UIImage imageNamed:#"o13.png"];
UIImage* opa14 = [UIImage imageNamed:#"o14.png"];
UIImage* opa15 = [UIImage imageNamed:#"o15.png"];
UIImage* opa16 = [UIImage imageNamed:#"o16.png"];
UIImage* opa17 = [UIImage imageNamed:#"o17.png"];
UIImage* opa18 = [UIImage imageNamed:#"o18.png"];
NSArray *imgsArr = [NSArray arrayWithObjects:opa1, opa2, opa3, opa4,
opa5, opa6, opa7, opa8, opa9, opa10, opa11, opa12, opa13, opa14, opa15, opa16, opa17, opa18, nil];
[aniImage setAnimationImages:imagesOpcaity];
[aniImage setAnimationRepeatCount:1.0];
[aniImage setAnimationDuration:0.2];
If you wants to see all the images they are using follow these setps -
1) buy the free version on your iPhone/iPad
2) transfer your purchases on your mac or windows.
3) then drag the ipa file from Library -> Apps to your desktop (just drag the app icon from iTunes to desktop)
4) rename the .ipa file to .zip file
5) extract this zip file.
6) you will get a folder named "Payload" in it.
7) open the .app file (it will open on windows automatically because it is a folder on windows, on mac right click on it and select show package content.
8) in the .app folder you will find a folder which contains all the images used by above function.
Hope it helps
There are 2 approaches
One - make them as 3d Models with animations. The best suited too for this is Unity3d (it brings down development time to a great extent) But the basic version for iPhone to publish costs 400$. I think its worth it.
Two - Make all of them as frame animations. Use either Cocos2d or UIImageView's frames to animate it. You need to dealloc and alloc on the fly when you have too many frames due to which you might hit memory warning. You might think loading on the fly would be costly/intensive but its not as much as you would expect, as iDevices have flash memory on them and we have tried this.
I personally would say use 2nd method if you need just a clone. But with 3d models with animations in them, you get more freedom to add creativity like a 3d camera to look around. So you can poke in the butt and have a different animation for it etc. Also you could have overlay texture and do things like adding tattoos to the 3d model.
You can make Tap Zoo and other by using images or sprite sheets may be on UIButton or enable user interaction for images. but you have to use alot of coding to implement some like that big, it wouldn't be difficult to accomplish it just many lines of code(seriously many more than 100K). So take my advise and learn cocoa2d or quartzcore2d or opengl that way you will not only learn something new but also be able to make nice games. for opengl start up follow this link
http://appstapnet.blogspot.in/2009/04/opengl-es-from-ground-up-part-1-basic.html?m=1

iphone OS 4.0- issues in displaying higher resolution images

I am using the new Retina display feature of ios 4.0 in my iphone application.
I added the images for higher resolution with the naming convention as image#2x.png to my existing image folder.
eg. I am adding the image in the following way:
UIImageView *toolBarBg=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,88) ];
NSString *toolBarBgImgPath=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:#"bg_btm_bar.png"];
[toolBarBg setImage:[UIImage imageWithContentsOfFile:toolBarBgImgPath]];
I am having the image named "bg_btm_bar#2x.png" in my image folder as well.
But when I am running my application it is not taking the higher res image.
I am not understanding that how to make the application use the higher res image.
Please help me out!
Use imageNamed: instead of imageWithContentsOfFile:

Customizable non-full screen video player in iPhone

I know that there is an MPMoviePlayerController present in iPhone to play movies from. But it isn't customizable in the real sense. Also, if I wanted to play movies is a non-full screen mode, it isn't possible today.
I wanted to inquire if anyone knows about the future roadmap of iPhone SDK, is there going to be any such customizable video player upcoming?
Also, is it possible to write a new video player from scratch (maybe including the codecs), then in that case which part of the SDK should be referred to and how?
Some help in this area will be really appreciated.
Thanks,
Saurabh
I don't know of anything in the future about a customizable video player. However, if there are just a few videos you want to play in non-fullscreen mode, there is an option. UIImageView supports animation. So, if you can export your videos as images, you can have them display in an UIImageView.
For example,
//load your images here
youImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
youImageView.animationDuration = 1; //this is the duration of the animation and can be any value
[youImageView startAnimating];
This blog post http://www.nightirion.com/2010/01/scaling-a-movie-on-the-iphone/ mentions a method that will allow you to play non-fullscreen video. However, I'm not sure if this method will be approved by the app store verification process.

How do I test a camera in the iPhone simulator?

Is there any way to test the iPhone camera in the simulator without having to deploy on a device? This seems awfully tedious.
There are a number of device specific features that you have to test on the device, but it's no harder than using the simulator. Just build a debug target for the device and leave it attached to the computer.
List of actions that require an actual device:
the actual phone
the camera
the accelerometer
real GPS data
the compass
vibration
push notifications...
I needed to test some custom overlays for photos. The overlays needed to be adjusted based on the size/resolution of the image.
I approached this in a way that was similar to the suggestion from Stefan, I decided to code up a "dummy" camera response.
When the simulator is running I execute this dummy code instead of the standard "captureStillImageAsynchronouslyFromConnection".
In this dummy code, I build up a "black photo" of the necessary resolution and then send it through the pipelined to be treated like a normal photo. Essentially providing the feel of a very fast camera.
CGSize sz = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) ? CGSizeMake(2448, 3264) : CGSizeMake(3264, 2448);
UIGraphicsBeginImageContextWithOptions(sz, YES, 1);
[[UIColor blackColor] setFill];
UIRectFill(CGRectMake(0, 0, sz.width, sz.height));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
The image above is equivalent to a 8MP photos that most of the current day devices send out. Obviously to test other resolutions you would change the size.
I never tried it, but you can give it a try!
iCimulator
Nope (unless they've added a way to do it in 3.2, haven't checked yet).
I wrote a replacement view to use in debug mode. It implements the same API and makes the same delegate callbacks. In my case I made it return a random image from my test set. Pretty trivial to write.
A common reason for the need of accessing the camera is to make screenshots for the AppStore.
Since the camera is not available in the simulator, a good trick ( the only one I know ) is to resize your view at the size you need, just the time to take the screenshots. You will crop them later.
Sure, you need to have the device with the bigger screen available.
The iPad is perfect to test layouts and make snapshots for all devices.
Screenshots for iPhone6+ will have to be stretched a little ( scaled by 1,078125 - Not a big deal… )
Good link to a iOS Devices resolutions quick ref : http://www.iosres.com/
Edit : In a recent project, where a custom camera view controller is used, I have replaced the AVPreview by an UIImageView in a target that I only use to run in the simulator. This way I can automate screenshots for iTunesConnect upload. Note that camera control buttons are not in an overlay, but in a view over the camera preview.
The #Craig answer below describes another method that I found quite smart - It also works with camera overlay, contrarily to mine.
Just found a repo on git that helps Simulate camera functions on iOS Simulator with images, videos, or your MacBook Camera.
Repo