| Home 目次>ApplicationKit>NSImage | |
compositeToPoint:fromRect:operation:
表示範囲、合成方法を指定して画像を表示します
-(void) compositeToPoint:(NSPoint)aPoint
fromRect:(NSRect)aRect
operation:(NSCompositingOperation)op
【返り値】 | |
| void | なし |
| 【パラメータ】 | |
| aPoint | 表示位置 |
| aRect | 表示範囲 |
| op | 合成方法 |
【解説】
画像を表示範囲を指定して合成して表示します
【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];
//合成後のimgをImageViewに表示する
[image setImage:img];
//imgを描画から外す
[img unlockFocus];
}
}
@end
![]() | |
この記事を評価してください。
| Home 目次>ApplicationKit>NSImage | 修正日2006.12.26 |