English 中文(简体)
哪一种方法能较好,为什么?
原标题:Which method to resize UIImage is better and why?

对所有各位制图专家来说,我很想知道,这两种方法中哪一种方法能更好地改造UIImage:

第一个我到场是简单而受欢迎的,是:

-(UIImage *)resizeImage:(UIImage *)image width:(CGFloat)resizedWidth height:(CGFloat)resizedHeight
{
    UIGraphicsBeginImageContext(CGSizeMake(resizedWidth ,resizedHeight));
    [image drawInRect:CGRectMake(0, 0, resizedWidth, resizedHeight)];
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return result;
}

The second means I found in this connection ,并且似乎与上述目标相同,但比较复杂(我不真正理解其中的内容):

-(UIImage *)resizeImage:(UIImage *)image width:(CGFloat)resizedWidth height:(CGFloat)resizedHeight
 {
    CGImageRef imageRef = [image CGImage];

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef bitmap = CGBitmapContextCreate(NULL, resizedWidth, resizedHeight, 8, 4 * resizedWidth, colorSpace, kCGImageAlphaPremultipliedFirst);
    CGContextDrawImage(bitmap, CGRectMake(0, 0, resizedWidth, resizedHeight), imageRef);
    CGImageRef ref = CGBitmapContextCreateImage(bitmap);
    UIImage *result = [UIImage imageWithCGImage:ref];

    CGContextRelease(bitmap);
    CGImageRelease(ref);

    return result;  
}

因此,我的问题是,什么方式更好,为什么?

问题回答

第二种是安全的。

这是一个相当晚的答复,但我只想再作一番。

我实际上发现两种方法之间除预先判断外的一些行为差异。

在一部照片中,我有照相机,把任何照相图像传送给一名定制图像编辑。 照片中,习俗照相/编辑的观点是独一无二的。 然而,本土照相机窗本身是NOT。

因此,每当发现照片时,最终结果就会被歪曲。 这些扭曲现象很容易地通过滑坡和高潮处理,无论在什么时候,都会 w;高。

上述两种方法(简单一)的第一个方法产生了90度轮值的图像,仍然被歪曲。 然而,第二位人完全改变了形象!

我认为,这与基于背景的图示行为有关。 第二种方法没有利用这一背景,在我的案件中毫无效果地运作。

It s a high-level and a low-level approach.

Which is better? Depends on your goal.

高级别办法更可读(对我而言),因为低级办法可能较快(didn t test)。

很难判断算法......





相关问题
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, ...

热门标签