drawInRect:fromRect:operation:fraction:
部分的に合成方法、範囲を指定して画像を合成します
-(void)drawInRect:(NSRect)rect: fromRect:(NSRect)fromRect: operation:(NSCompositingOperation)op: fraction:(float)delta:
解説
部分的に合成方法、範囲を指定して画像を合成します。(NSAffineTransformで回転を適用可能)
【NSCompositingOperation】合成方法
● NSCompositeClear クリアする
● NSCompositeCopy 透明度を無視して上書きする
● NSCompositeSourceOver 透明度を考慮してして上書きする
● NSCompositeDestinationOver
● NSCompositeSourceIn 透明度を無視して上書きする
● NSCompositeDestinationIn 色があるところは切り抜き
● NSCompositeSourceOut クリアする
● NSCompositeDestinationOut 色があるところはクリア
● MSCompositeSourceAtop 透明度を考慮してして上書きする
● NSCompositeDestinationAtop
● NSCompositeXOR
● NSCompositePlusDarker
● NSCompositeHighlight
● NSCompositePlusLighter
NSAffineTransformで回転させる場合。
変換マトリックを作って、その後フォーカスしているビューにsetする。
NSAffineTransform *affin = [NSAffineTransform transform];
[affin rotateByDegrees:10.0];
[affin set];
[thePath transformUsingAffineTransform: affin];
返り値
( void )
なし
引数
( NSRect )rect
表示先範囲
( NSRect )fromRect
表示元範囲
( NSCompositingOperation )op
合成方法
( float )delta
不透明度
フレームワーク
ApplicationKit
クラス
NSImage
Instance Methods
使用可能
10.0
参照
- dissolveToPoint:fraction:
例文
#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 drawInRect:NSMakeRect(100.0,100.0,160.0,160.0) fromRect:NSMakeRect(0.0,0.0,80.0,80.0) operation:NSCompositeXOR fraction:0.5 ]; //合成後のimgをImageViewに表示する [image setImage:img]; //imgを描画から外す [img unlockFocus]; } } @end