- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Core Image 和 Lanczos Scale Transform 过滤器进行图像缩放。当我进行放大时,这很好。但在缩小并保存为 JPEG 时,我发现一类图像会产生奇怪的噪声伪影和行为。
对于 inputScale 倍数为 0.5:0.5、0.25、0.125 等,总是没问题的。对于其他 inputScale 值,它已损坏。
当我保存为 TIFF、PNG、JPEG2000 或在屏幕上绘图时 - 没问题。当我保存为 JPG 或 BMP 时 - 它损坏了。
我上传了示例图片:(original, 4272x2848, 3.4Mb)[http://www.zoomfoot.com/get/package/517e2423-7795-4239-a166-03d507ec51d8]
( scaled with noise, 1920x1280, 2.2Mb )[http://www.zoomfoot.com/get/package/6eb64d33-3a30-4e8d-9953-67ce1e7d7ef9]
它在“日落”图像上的重现性也相当好。
我尝试了更多缩放图像的方法。使用 CIAffineTransform 并使用 NSImage 本身进行绘图。两者都提供没有任何噪音的结果。
这是我用于缩放和保存的代码:
================== 兰佐斯 =============
<br/>
- (NSImage *) scaleLanczosImage:(NSString *)path
Width:(int) desiredWidth
Height:(int) desiredHeight
{
CIImage *image=[CIImage imageWithContentsOfURL:
[NSURL fileURLWithPath:path]];<p></p>
<p>CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
int originalHeight=[image extent].size.height;
int originalWidth=[image extent].size.width;</p>
<p>float yScale=(float)desiredHeight / (float)originalHeight;
float xScale=(float)desiredWidth / (float)originalWidth;
float scale=fminf(yScale, xScale);</p>
<p>[scaleFilter setValue:[NSNumber numberWithFloat:scale]
forKey:@"inputScale"];
[scaleFilter setValue:[NSNumber numberWithFloat:1.0]
forKey:@"inputAspectRatio"];
[scaleFilter setValue: image
forKey:@"inputImage"];</p>
<p>image = [scaleFilter valueForKey:@"outputImage"]; </p>
<p>NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCIImage:image];
NSMutableDictionary *options=[NSMutableDictionary dictionaryWithObject:[NSDecimalNumber numberWithFloat:1.0]
forKey:NSImageCompressionFactor];</p>
<p>[options setValue:[NSNumber numberWithBool:YES] forKey:NSImageProgressive];
NSData* jpegData = [rep representationUsingType:NSJPEGFileType
properties:options];</p>
<p>[jpegData writeToFile:@"/Users/dmitry/tmp/img_4389-800x600.jpg" atomically:YES];
} </p>
<h1></h1>
================= NSImage =============
<br/>
- (void) scaleNSImage:(NSString *)path
Width:(int) desiredWidth
Height:(int) desiredHeight
{
NSImage *sourceImage = [[NSImage alloc] initWithContentsOfFile:path];
NSImage *resizedImage = [[NSImage alloc] initWithSize:
NSMakeSize(desiredWidth, desiredHeight)];<p></p>
<p>NSSize originalSize = [sourceImage size];</p>
<p>[resizedImage lockFocus];
[sourceImage drawInRect: NSMakeRect(0, 0, desiredWidth, desiredHeight)
fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height)
operation: NSCompositeSourceOver fraction: 1.0];</p>
<p>[resizedImage unlockFocus];</p>
<p>NSMutableDictionary *options=[NSMutableDictionary dictionaryWithObject:[NSDecimalNumber numberWithFloat:1.0]
forKey:NSImageCompressionFactor];</p>
<p>[options setValue:[NSNumber numberWithBool:YES] forKey:NSImageProgressive];</p>
<p>NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithData:[resizedImage TIFFRepresentation]];</p>
<p>NSData* jpegData = [rep representationUsingType:NSJPEGFileType
properties:options];</p>
<p>[jpegData writeToFile:@"~/nsimg_4389-800x600.jpg" atomically:YES];</p>
<p>} </p>
<h1></h1>
如果有人可以在这里解释或提出一些建议,我真的很感激。
谢谢。
最佳答案
使用 CIImage 进行缩放有一些怪癖。会this丹·伍德 (Dan Wood) 的帖子 有帮助吗?
关于cocoa - CILanczosScaleTransform 后出现奇怪的现象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2206743/
我正在尝试使用 Core Image 和 Lanczos Scale Transform 过滤器进行图像缩放。当我进行放大时,这很好。但在缩小并保存为 JPEG 时,我发现一类图像会产生奇怪的噪声伪影
我正在尝试使用 CILanczosScaleTransform Core Image Filter 来调整图像大小,但我遇到了问题。这是我的代码: var imageView: UIImageView
我是一名优秀的程序员,十分优秀!