Why is my UIImageView blurred?

Posted by Denis M on Stack Overflow See other posts from Stack Overflow or by Denis M
Published on 2009-08-09T04:56:19Z Indexed on 2010/03/13 12:45 UTC
Read the original article Hit count: 345

I have a really weird problem with UIImageView. I have an image (an RGB png) 45x45 pixels which I add to the view. I can see that image is blurred after added to the view. Here is the same image in the simulator (left) and in Xcode (right):

alt textalt text

I have custom UIImageView class with this initWithImage code:

- (id) initWithImage:(UIImage*) image {
    self = [super initWithImage:image];

    self.frame = CGRectMake(0, 0, 45, 45);
    self.contentMode = UIViewContentModeScaleAspectFit;

    self.quantity = 1;
    if (self) {
        self.label = [[UITextField alloc]initWithFrame:CGRectMake(0,40,45,25)];
        self.label.font = [UIFont systemFontOfSize:16];
        self.label.borderStyle = UITextBorderStyleNone;
        self.label.enabled = TRUE;
        self.label.userInteractionEnabled = TRUE;
        self.label.delegate = self;
        self.label.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        self.label.textAlignment = UITextAlignmentCenter;
    }
    self.userInteractionEnabled = TRUE;

    // Prepare 3 buttons: count up, count down, and delete
    self.deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.deleteButton.hidden = NO;
    self.deleteButton.userInteractionEnabled = YES;
    self.deleteButton.titleLabel.font  = [UIFont systemFontOfSize:20];
    self.deleteButton.titleLabel.textColor = [UIColor redColor];
    [self.deleteButton setTitle:@"X" forState:UIControlStateNormal];
    [self.deleteButton addTarget:self action:@selector(deleteIcon:) forControlEvents:UIControlEventTouchUpInside];

    self.upCountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.upCountButton.hidden = NO;
    self.upCountButton.userInteractionEnabled = YES;
    [self.upCountButton setTitle:@"+" forState:UIControlStateNormal];
    [self.upCountButton addTarget:self action:@selector(addQuantity:) forControlEvents:UIControlEventTouchUpInside];

    self.downCountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.downCountButton.hidden = YES;
    self.downCountButton.userInteractionEnabled = YES;
    [self.downCountButton setTitle:@"-" forState:UIControlStateNormal];
    [self.downCountButton addTarget:self action:@selector(removeQuantity:) forControlEvents:UIControlEventTouchUpInside];
    return self;
}

I create it like this:

UIImage *desertIcon = [UIImage imageNamed:@"desert.png"];
IconObj *desertIconView = [[IconObj alloc] initWithImage:desertIcon];
desertIconView.center = CGPointMake(265,VERTICAL_POINT_ICON);
desertIconView.type = [IconObj TYPE_DESERT];
[self.view addSubview:desertIconView];
[desertIconView release];

Why would the displayed image be so than the one stored in a file?

© Stack Overflow or respective owner

Related posts about uiimageview

Related posts about objective-c