English 中文(简体)
能否在不失去质量的情况下重新使用UIImage?
原标题:Is it possible to resize a UIImage without losing quality?

我用“UIImage”的话说,我用上了一张带有骨折射镜的pin子,我用这个镜子来提升形象。 当我对UIImage语的图像作一番说明时,就不存在歪曲,而且其规模完全是完美的。 然而,在《UIImage案》中,我需要改写“UIImage”一词,如果我使用以下代码这样做的话,结果会稍有失:

CGFloat width = self.imageView.frame.size.width;
CGFloat height = self.imageView.frame.size.height;

UIGraphicsBeginImageContext(CGSizeMake(width, height));
[self.image drawInRect:CGRectMake(0, 0, width, height)];
UIImage *resizedImage = [UIGraphicsGetImageFromCurrentImageContext() retain];    
UIGraphicsEndImageContext();

你们可以看到,我从图像学中走高和高潮,因为需要扩大形象。

我知道,如果图像成像,就必须能够完美地加以推广。 能够这样做,任何人都不知道我做什么是不正确的?

UPDATE: I annex a before / after of an pornography ( which has been repled by theuser in angramview) and how it look after I reize it using the above methods. “Before”/“After”/

问题回答

为此:

+ (UIImage*)rescaleImage:(UIImage *)image scaledToSize:(CGRect)newSize {
    UIGraphicsBeginImageContext(newSize.size);
    [image drawInRect:newSize];
    UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resImage;
}

我有同样的问题,我使用了以下法典来帮助确定:

    CGFloat scale = 1.0;
if([[UIScreen mainScreen]respondsToSelector:@selector(scale)]) {        
    CGFloat tmp = [[UIScreen mainScreen]scale];
    if (tmp > 1.5) {
        scale = 2.0;    
    }
} 

if(scale > 1.5) {
    UIGraphicsBeginImageContextWithOptions(targetSize, NO, scale);
} else {
    UIGraphicsBeginImageContext(targetSize);
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签