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

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
I have an UIImageView which holds an image inside, but the image looks very blurred. I google around and most people say it's because of some frame parameters are not integer. However, i'm still not clear about the answer.

Can anyone explain it for me ? Thanks a lot.
 
Basically, you might have something like this:
Code:
CGFloat xOrigin = 25.352;        // will result in a blurred image

To fix this, you might do something like this:
Code:
CGFloat xOrigin = 25.352;
xOrigin = (CGFloat)(int)xOrigin;        // xOrigin is now 25.0
 
Another problem which may have caused this is if you added the image before you removed the status bar at the top of the image....in which case just remove the UIImageView and add it again.
 
Basically, you might have something like this:
Code:
CGFloat xOrigin = 25.352;        // will result in a blurred image

To fix this, you might do something like this:
Code:
CGFloat xOrigin = 25.352;
xOrigin = (CGFloat)(int)xOrigin;        // xOrigin is now 25.0

Hi,

Can you explain what 'xOrigin' is ? Is it the X origin of the UIImageView ?
Thanks.
 
The floating point frame dimensions does not fully address this problem.

I have also had problems with blurred images under varying circumstances.

If I add images to a UIPickerview they are sharp.

If I add the same images to a UIView programmatically they are blurred, but not all of them, some images are sharp.

If I add the same images to the same UIViews using Interface Builder they are sharp.

There is some sort of quirckyness going on under the hood.
 
Show a screen shot of the problem.

In viewWillAppear print out the frame of your imageview and let us know what it is. Also, print out the size of the image.
 
I have done more troubleshooting with this problem in regards to the issues I am experiencing.

I discovered that the size of the UIImageView frame containing the image can cause pixel resampling.

Even with the contentMode set to center, when I resize the frame manually I can see the image change sharpness in and out. The best frame setting to insure exact original image sharpness is to match the frame size to the image size. So if your image is 60 x 60 pixels then the frame size should be 60 x 60.

This will work if you create the view in Interface Builder, but I also discovered that it still will not render sharp if the view is created programmatically.

I created similar imageViews the same size as in IB programmatically and they came out blurry, even though I matched the frame size to the image size.

This occurs in the regular iPhone device setting in the simulator.
If I switch to iPhone 4 in the simulator, then all images render sharp no matter what size the imageView frame is.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.