macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

setImageScaling:

スケーリングモードをセットします
-(void)setImageScaling:(NSImageScaling)scaling:

解説

スケーリングモードをセットします。
【NSImageScaling】
● NSScaleProportionally 縦横比を維持してNSImageViewに合わせます
● NSScaleToFit NSImageViewに合わせる縦横比は無視する
● NSScaleNone 拡大縮小せずそのまま
初期設定は、NSScaleProportionallyです。

返り値

( void )

なし

引数

( NSImageScaling )scaling

スケーリングモード 下記参照

フレームワーク

ApplicationKit

クラス

NSImageView

Instance Methods

使用可能

10.0

参照

- imageScaling

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
    //開けるファイル拡張子の配列
    NSArray      *imgTypes    = [ NSArray arrayWithObject : @"tiff" ];
    //OpenPanelを作る
    NSOpenPanel  *opImage       = [ NSOpenPanel openPanel ];
    //Imageを作る
    NSImage      *img;
    
      NSImage      *Copyimg;

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

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        //NSImageを作ってファイルから読み込む
        img = [ [ NSImage alloc ] 
                          initWithContentsOfFile: [ opImage filename ] ];
        //レシーバimage(NSImageView)にimgをセットする
        [image1 setImage : img ];
        
        Copyimg =  [ NSImage alloc ];
        Copyimg = [image1 image];
        [image1 setImageScaling : NSScaleToFit ];  
        [image2 setImage : Copyimg ];
        [image2 setImageScaling : [image1 imageScaling] ];                          
    }
}

@end