NSImage:compositeToPoint:fromRect:operation:fraction:
Home 目次>ApplicationKit>NSImage

compositeToPoint:fromRect:operation:fraction:

表示範囲、不透明度、合成方法を指定して画像を表示する


-(void) compositeToPoint:(NSPoint)aPoint
   fromRect:(NSRect)aRect
   operation:(NSCompositingOperation)op
   fraction:(float)flaction


【返り値】
   voidなし
【パラメータ】
   aPoint表示位置
   aRect表示範囲
   op合成方法
   flaction不透明度


【解説】

表示範囲、不透明度、合成方法を指定して画像を表示する
【NSCompositingOperation】合成方法
● NSCompositeClear クリアする
● NSCompositeCopy 透明度を無視して上書きする
● NSCompositeSourceOver 透明度を考慮してして上書きする
● NSCompositeDestinationOver
● NSCompositeSourceIn 透明度を無視して上書きする
● NSCompositeDestinationIn 色があるところは切り抜き
● NSCompositeSourceOut クリアする
● NSCompositeDestinationOut 色があるところはクリア
● MSCompositeSourceAtop 透明度を考慮してして上書きする
● NSCompositeDestinationAtop
● NSCompositeXOR
● NSCompositePlusDarker
● NSCompositeHighlight
● NSCompositePlusLighter



【例文】


#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
//開けるファイル拡張子の配列
NSArray *imgTypes = [ NSArray arrayWithObject : @"tiff" ];
//OpenPanelを作る
NSOpenPanel *opImage = [ NSOpenPanel openPanel ];
//Imageを作る
NSImage *img;
NSImage *img2;
//OpenPanelの結果のボタン番号
int opRet;

//OpenPanelでファイル選択
opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
file : @"Pictures" //どのどのファイルを選択しておくか
types : imgTypes ];//選べるファイルタイプ

if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら
//NSImageを作ってファイルから読み込む
img = [ [ NSImage alloc ]
initWithContentsOfFile: [ opImage filename ] ];
//NSImageをバンドルファイルからつくる
img2 = [NSImage imageNamed: @"NSApplicationIcon" ];

//imgを描画対象にする
[img lockFocus];
//描画対象にimg2を合成する
[img2 compositeToPoint:NSMakePoint(10,100)
fromRect:NSMakeRect(0.0,0.0,80.0,80.0)
operation:NSCompositeSourceOver
fraction:0.5];
//合成後のimgをImageViewに表示する
[image setImage:img];
//imgを描画から外す
[img unlockFocus];
}
}

@end


(C) 2000-2007 Satoshi Oomori.
[Apple]

Google
Webwww.oomori.com
Apple_Store_40x120

[ad:Usual day in Japan]

この記事を評価してください。 

良い 

間違いがある 説明がわかりにくい 例文がわかりにくい  

Home 目次>ApplicationKit>NSImage
修正日2006.12.26