Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newbRacer

macrumors newbie
Original poster
Jul 30, 2009
6
0
Singapore
Hi, I am new to the iPhone SDK and I want to add in an image background using UIKit or OpenGL (are they the same thing?).:confused:

Basically it is a static image that is going to be the bottommost layer.

What is the easiest method to load the image and render it out?

Please help me out. Thank you.
 
UIImageView is what you use for an image layer in the UIKit.
You can simply set load the image with the setImage method.
Code:
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage: [UIImage imageNamed:@"imageInBundle.png"]];
[viewToAddImageTo addSubview: imageView];

Loading a texture is a bit more complex in OpenGL. Apple has an example project creating a texture for OpenGL. It is for mac but the code would be nearly identical for iPhone. CoreImageGLTextureFBO
 
UIImageView is what you use for an image layer in the UIKit.
You can simply set load the image with the setImage method.
Code:
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage: [UIImage imageNamed:@"imageInBundle.png"]];
[viewToAddImageTo addSubview: imageView];

Loading a texture is a bit more complex in OpenGL. Apple has an example project creating a texture for OpenGL. It is for mac but the code would be nearly identical for iPhone. CoreImageGLTextureFBO

I see... so means by using the above 3 lines, I will already be loading and rendering the graphics. Am I right to say that?

Thank you for your help. :D
 
You can also add a UIImageLayer using Interface Builder. If the image is already part of your project, the image will appear under the Media list in the Library window. You can simply drag the image to your window and resize it how you like. Note that it will be stretched to fit, so you should resize the image beforehand to exactly the size you need.
 
You can also add a UIImageLayer using Interface Builder. If the image is already part of your project, the image will appear under the Media list in the Library window. You can simply drag the image to your window and resize it how you like. Note that it will be stretched to fit, so you should resize the image beforehand to exactly the size you need.

Thank you for the other suggestion. It would be very helpful if you could link me to a tutorial or give me tips on how I could do it the Interface builder method.

Thank you once again. Really appreciate your help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.