![](/img/trans.png)
[英]How to draw an tiled background image with alpha transparency on iPhone OS?
[英]Draw image with transparency
我有一些png,它們彼此疊加以在beginGraphicsContextWithOptions中形成單個圖像。...但是,我想以透明性繪制其中的某些圖像。 我該怎么做?
這是使用透明圖像疊加圖像的方法:
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.