For UIImage, use of #2x w/o duplicating files - iphone

Beginner here. My app shows an UIImage (in a scroll view).
If you are on retina device, then it should not scroll and I set the scroll view frame to be
the exact size (640x960).
If you are not on a retina device then it should scroll, so I set the scroll view frame to the pixels (480x320).
I have this working by setting the frame sizes, as mentioned, in viewDidLoad()
So...my question is that I have to keep both images on disk. I have pix.png and pix#2x.png and they are exactly the same thing.
Any help on how to handle this? Maybe it is obvious, but not to me ;-)
thx!

In my opinion,If you load the image with the two file name, I think you should keep them on disk.If not, you can delete one of them. Nomatter what pixels size you set, the original pixels datas are always which image file you load from disk.

No, you shouldn't need two copies of the same image. The #2x scheme is just lets you automatically load a high resolution image when one is available. It sounds like you're already managing your scroll view's content size and things are working, so you can just get rid of the pix#2x.png file.
I'm not sure it's a great UI decision to change the app's behavior based on its screen resolution, though. Since you're already using a scroll view, it can be easy for the user to zoom in and out. Non-retina devices will display at native resolution when zoomed in; retina devices will display at native resolution when zoomed out.

Related

UIImageView PNG pixelation on iOS simulator and on device

This may be a very simple issue, but I've been stuck with this for a week. I'm using an UIImageView to display a Dropbox branding PNG image. I see it alright in Interface Builder, but it's easy to notice a strong pixelation in the iOS Simulator and in the actual device (an iPad). Here I attach a screen capture of the IB together with the simulator:
I would really appreciate any hint.
Thanks in advance!
InterfaceBuilder is a completely different environment than iOS or even the simulator. Layout and such should translate, but the way everything looks should always be judged (and therefore designed for) the end product.
It looks like your image is being stretched slightly. There are any number of reasons for this. The first thing to check is the resizing mask on your UIImageView. It's generally bad for UIImageViews to autoresize - for this very reason.
By the way, autoresizing is UIKit's way of making sure that subviews still fit/look good when their parent view changes size. You can specify how much you want a subview to move around, also how much you want it to stretch. Read about it here.
What you will want to do is design your view -- answer the question: how big do I want this image to be in the final product? -- and then make the actual png that size (also produce an #2x variant that is double the size for retina displays). Then, when you design in IB, make your UIImageView that size as well, and make sure that the autoresizing settings are set to prohibit stretching.
This ought to fix your problem.
Check to make sure the size of the image matches the size of your UIImageView. If the image happens to be smaller than the target image view, it will stretch to fill it which could cause pixelation. Also, if you are running the new 5.1 Simulator for iPad, it will default to the new retina screen, which means you will need the #2x sized images to prevent pixelation there.

Why is a picture appearing blurry on the iphone (no scaling)

I have been doing a bit of testing with images today and found that I could not make a blurry PNG image, which looked fine on my desktop appear non-blurry on the iphone without doing some strange things.
It wasn't until I made the images twice the resolution, then resized them within the iphone that they appeared crisp on screen. Is that normal practice?
What say if you have a background image that you want to be non-blurry? I don't see how I can do something like upload a background image and tell it to run at half the size...
Thanks for any pointers!
I found the answer.
It turns out that pixels are not the same on the iphone and are actually at a higher resolution.
In order to make images non-blurry, I needed to basically upload images 2-3 times regular size and then make their size smaller within the CSS.
For example, if I wanted a 50px image, I uploaded a 100px image and styled in within css to have a width of 50px.
It looks like the new iPads have even higher resolutions which means you may even want to upload higher resolution images to cater to those.
A bit lame I think, but it does look nice.
I might be misunderstanding you, but if you'd like to present a crisp image on a retina phone, you can place it in a UIImageView half it's size and set the contentMode to scale to fill.

Blurry images when running my application on iPhone

So, I was creating an application for iOS with Xcode 4.2.1, I don't know why all of my icons are blurry, they are in high definition, but for some reason they looks blurry and in a bad quality.
even the background images looks bad..
Please help me, what can I do about it?
This is the original button image:
This is how it looks on the application:
Make sure you saved the high-resolution images with the ending #2x.png, if they aren't they won't work. Also remember that the images needs to be twice the size of the pixles on the screen, that means a 50px x 50px-button will need a 100px x 100px-#2x-file.
Read more about retina icons in the iOS Documentation here.
You should round the origin of each image. If you place image with coordinate like (250.34, 340.21) you get blurry effect.
This is very likely to happen when you use automatic position calculation as well as center property to place your views/images.
In the simulator, use the new Debug menu to check whether your images are misaligned. If they are, use NSRectIntegral to fix their frames.

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.

Interface Builder can't display 160dpi images correctly?

I'm developing an iPhone app. A simple image is the background of the main view.
I've set an UIImageView in the background and set an image in, using IB.
the image is a 160dpi PNG image. It appears like CRAP in IB. When running in the simulator it is ok, crisp.
How am I supposed to work and place my controls precisely on a such poor resolution image ?
Is this a bug ?
Thanks for you help!
IB is not a tool for designing a UI, it is a tool for implementing one. It is designed to perform well rather than display well (this is more important in complex desktop UI design than mobile but the tool is the same for both). The best advice is perhaps to take a cue from the publishing world (where this is a common practice for applications that display large amounts of high resolution graphics such as Adobe InDesign) and keep track of exact measurements for controls - the x,y coordinate positions and height/width. Then you can use the inspector to precisely position controls.
Actually, the DPI is not irrelevant at all.
Change the DPI to 72 and the image will display in IB/Xcode fine.
I don't see anything like this when I work with images in IB. Maybe there's something special about your PNG file? You say that it's 160 dpi, which is fairly irrelevant. More important are what its pixel diomensions are, and how they compare to the screen size.
Maybe the UIImageView is having trouble rendering your PNG, and is for some reason using the preview icon instead? Try a different image, or try resizing your image to 480x320, with 32-bit color.
I am wondering about this as well. I don't think the DPI of the image is what is doing this, because I have a project where everything looks fine in IB on one machine, then on my laptop, it displays the way the OP is describing.
The image dimensions are the same as the iPhone screen and the view dimensions (320x480), but the image displays all tiny instead of filling up the whole dimeal nsions of the UIImageView. If I scale to fill, then the image gets all blurry, at 320x480, even though I can confirm that those are the actual dimensions of the image... It's acting as if the image itself is 320x480 of empty space with a small version of my image centered inside it... this is very strange. As I said- this is the same project that looks completely fine in IB on another machine (and when they build, they both look normal in the simulator). This also happens on my friends's macbook.
Is there some setting in IB that might be the difference?
EDIT:
Guess I spoke too soon- I went back to my other machine and noticed the same problem this time, and it indeed was the dpi. This must have been a change in one of the recent updates to xcode/IB, because I originally never saw this issue, and the image files are exactly the same... strange.