NSImage drawAtPoint失去了质量

时间:2014-03-08 08:00:23

标签: objective-c macos nsimage

我有一张单色照片,当我把这张照片画到另一张照片时,它变成了灰色的照片。

这是我的代码:

保存单色照片:

        NSImage *copyImage = [image copy];  // Copy from a monochrome picture
        NSBitmapImageRep *copyrep = [[NSBitmapImageRep alloc] initWithData:[copyImage TIFFRepresentation]];
        NSSize copySize;
        copySize.width = 72.0 * [copyrep pixelsWide] / PRINT_DPI;  //Set Printing DPI
        copySize.height = 72.0 * [copyrep pixelsHigh] / PRINT_DPI; //Set Printing DPI
        [copyrep setSize:copySize];
        copyImage= [[NSImage alloc] initWithData:[copyrep TIFFRepresentation]];
        NSData *imgData = [copyImage TIFFRepresentation];
        [imgData writeToFile: @"/Users/bbmac/Desktop/1.png" atomically: NO]; // save for testing

但是当我把它画成一张大图时,它就变成了灰色图片:

// for printing
NSImage *printImage = [[NSImage alloc] initWithSize:imageSize];
[printImage lockFocus];

// Draw a monochrome picture
[image drawAtPoint:NSMakePoint(newX, newY) fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0f];

[printImage unlockFocus]; 
// Save for testing
[[printImage TIFFRepresentation] writeToFile: @"/Users/bbmac/Desktop/printImage.png" atomically: NO];

0 个答案:

没有答案