【问题标题】:cocoa save CIImage as bmp file image corruptedcocoa 将 CIImage 保存为 bmp 文件 图像损坏
【发布时间】:2015-03-27 15:28:49
【问题描述】:

在 OSX 10.9.5 上,我试图将使用 QTkit 抓取的图像保存为 BMP 文件,但只有当我保存为 bmp 文件时,图像文件输出才会被切片(损坏),像这样

http://imgur.com/ZuQ0NtC

但是如果我将图像保存为 TIFF 或 PNG 文件一切都可以,这里是一个示例

http://imgur.com/xjJNNRa

我使用的代码是

-UPDATE- 仅当我在 CIImage 上应用 CIfilter *I

时,图像才会损坏
CIImage *I;

I=[Video cropImg:I];
//saving to disk
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc]initWithCIImage:I];
NSImage *nsImage = [[NSImage alloc] initWithSize:rep.size];
[nsImage addRepresentation:rep];

NSData *imageData = [nsImage TIFFRepresentation];

imageData = [rep representationUsingType:NSBMPFileType properties:NULL];

if ([imageData writeToFile:targetPath atomically:NO]==NO)

{
    NSLog(@"Error file");
}

如果我将 NSBMPFileType 更改为 NSPNGFileType 图像没问题,但我需要 bmp 文件

【问题讨论】:

    标签: objective-c macos cocoa core-image


    【解决方案1】:

    也许,您应该跳过对“NSImage”的转换,因为下面的代码对我有用。

    I=[Video cropImg:I];
    NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]initWithCIImage:I];
    NSData *imageData = [rep representationUsingType:NSBMPFileType properties:NULL];
    [imageData writeToURL:fileURL atomically:YES];
    

    【讨论】:

    • 不,不行,在我的mac上图像被切片,你能告诉我你编译的是32还是64吗?你的mac的型号和你的xcode版本?
    猜你喜欢
    • 1970-01-01
    • 2012-04-16
    • 2021-09-26
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多