UIImageView : blurred image

Discussion in 'iOS Programming' started by namanhams, Dec 24, 2010.

  1. namanhams macrumors regular

    Joined:
    Jun 3, 2009
    #1
    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.
     
  2. (marc) macrumors 6502a

    (marc)

    Joined:
    Sep 15, 2010
    Location:
    the woods
    #2
    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
     
  3. MDiak47 macrumors newbie

    Joined:
    Dec 11, 2010
    #3
    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.
     
  4. namanhams thread starter macrumors regular

    Joined:
    Jun 3, 2009
    #4
    Hi,

    Can you explain what 'xOrigin' is ? Is it the X origin of the UIImageView ?
    Thanks.
     
  5. flummoxed macrumors member

    Joined:
    Nov 27, 2010
    #5
    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.
     
  6. namanhams thread starter macrumors regular

    Joined:
    Jun 3, 2009
    #6
    Is there any way to solve this problem ? Thanks.
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    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.
     
  8. flummoxed macrumors member

    Joined:
    Nov 27, 2010
    #8
    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.
     

Share This Page