gpt4 book ai didi

macos - 如何在Mac应用程序中的NSImage中创建水印

转载 作者:行者123 更新时间:2023-12-03 16:20:31 26 4
gpt4 key购买 nike

我正在 NSImage 中工作,我想在 NSImage 中创建水印,我该如何做到这一点.. 任何人都可以提出建议吗?

最佳答案

类似这样的事情:

float width = 10.0;
float height = 10.0;

NSImage *finalImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];

// obtain images - your sources may vary
NSImage *overlay = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:@"/path/to/overlay_image.jpg"]];
NSImage *mainImage = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:@"/path/to/main_image.jpg"]];

[finalImage lockFocus];

// draw the base image
[mainImage drawInRect:NSMakeRect(0, 0, width, height)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

// draw the overlay image at some offset point
[overlay drawInRect:NSMakeRect(10, 10, [overlay size].width, [overlay size].height)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

[finalImage unlockFocus];

NSData *finalData = [finalImage TIFFRepresentation];

[[[NSBitmapImageRep imageRepWithData:finalData] representationUsingType:NSJPEGFileType properties:nil] writeToFile:[NSString stringWithFormat:@"/path/to/folder/new_image.jpg"] atomically:YES];

关于macos - 如何在Mac应用程序中的NSImage中创建水印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12369302/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com