0

我在下面有以下代码。首先,在表格详细视图中,我捕获或加载图像(图像大小约为屏幕的 1/4),然后保存后图像将显示在 UITableView 中。到目前为止,一切似乎都很顺利。但是,当我按下 UITable 并尝试再次加载详细信息页面时。图像的分辨率降低。我猜它的大小与 TableView 中的大小相同。我可以知道我能做些什么来解决这个问题吗?

谢谢。

    -(void) ViewDidLoad{
       if ([currentPicture smallPicture])
                [imageField setImage:[UIImage imageWithData:[currentPicture smallPicture]]];
    }

- (IBAction)editSaveButtonPressed:(id)sender
            {

            // If we are adding a new picture (because we didnt pass one from the table) then create an entry
                if (!currentPicture)
                    self.currentPicture = (Pictures *)[NSEntityDescription insertNewObjectForEntityForName:@"Pictures" inManagedObjectContext:self.managedObjectContext];

        if (imageField.image)
        // Resize and save a smaller version for the table
                    float resize = 74.0;
                    float actualWidth = imageField.image.size.width;
                    float actualHeight = imageField.image.size.height;
                    float divBy, newWidth, newHeight;
                    if (actualWidth > actualHeight) {
                        divBy = (actualWidth / resize);
                        newWidth = resize;
                        newHeight = (actualHeight / divBy);
                    } else {
                        divBy = (actualHeight / resize);
                        newWidth = (actualWidth / divBy);
                        newHeight = resize;
                    }
                    CGRect rect = CGRectMake(0.0, 0.0, newWidth, newHeight);
                    UIGraphicsBeginImageContext(rect.size);
                    [imageField.image drawInRect:rect];
                    UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
                    UIGraphicsEndImageContext();

                    // Save the small image version
                    NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 1.0);
                    [self.currentPicture setSmallPicture:smallImageData];
                }
4

2 回答 2

2

[在此处输入链接描述][1]更改此行(NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 1.0); )通过以下行..

NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 0.0);

或者

NSData *smallImageData = UIImagePNGRepresentation(smallImage);

希望对你有帮助..

于 2012-04-23T04:42:27.867 回答
0

(^.^)“抱歉,我的英语不好,如果有人喜欢纠正我的编辑,我将不胜感激”

您是否尝试过使用一个 UIImageView 和他的属性 contentMode?像这样:

UIImageView *imagen = [[UIImageView alloc] initWithFrame:CGRectMake(X, Y, W, H)];
[imagen setContentMode:UIViewContentModeScaleAspectFit];
于 2012-04-23T04:17:44.667 回答