我有几个png,我在beginGraphicsContextWithOptions中相互叠加形成一个图像。但是,我想用透明度绘制一些这些图像。我该怎么办呢?
答案 0 :(得分:0)
以下是如何使用透明度叠加图像:
NSString* file1 = "your images file path";
NSRect largerect = NSRectMake(10,10,300,300);
NSString* file2 = "your images file path";
NSString* file3 = "your images file path";
NSString* file4 = "your images file path";
NSImage* img1 = [[NSImage alloc] initWithContentsOfFile:file1];
NSImage* img2 = [[NSImage alloc] initWithContentsOfFile:file1];
NSImage* img3 = [[NSImage alloc] initWithContentsOfFile:file1];
NSImage* img4 = [[NSImage alloc] initWithContentsOfFile:file1];
//the fraction parameter is just how transparent you want it so 1.0 is opaque and 0.0 you will not see the image
[image1 drawInRect: largeRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 0.8];
[image2 drawInRect: largeRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 0.6];
[image1 drawInRect: smallRect1
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 0.40];
[image2 drawInRect: smallRect2
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 0.40];