macOS/iOS API解説

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

目次

CGBitmapContextCreate()

INDEX>CoreGraphics> CGBitmapContext

__

解説

OpenCVによる画像処理入門 (KS情報科学専門書)

OpenCVによる画像処理入門 (KS情報科学専門書)


返り値

引数

参照

サンプル



//コンテキスト
	CGContextRef context = UIGraphicsGetCurrentContext();
   
    //描画する画像
    UIImage *nimage =[UIImage imageNamed:@"gazou.jpg"];
    
    CGContextRef bitmapContext;
	
	//コンテキストに線のカラーをセットします。
    float col[4];
    col[0] = 1.0;
    col[1] = 1.0;
    col[2] = 0.5;
    col[3] = 0.5;
    
    CGBitmapInfo theBitmapInfo =    kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst;
    //画像の色空間
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    bitmapContext = CGBitmapContextCreate(nil, 100.0, 100.0, 8, 800.0, space, theBitmapInfo);
    //AAAAAAAARRRRRRRRRGGGGGGGGBBBBBBBB
    
    //サポートされる色空間のリスト
    //   http://developer.apple.com/jp/qa/qa2001/qa1037.html
    
    CGContextDrawImage (bitmapContext, CGRectMake( 0,0,100.0,100.0 ), [nimage CGImage]);
    CGImageRef cgImage = CGBitmapContextCreateImage( bitmapContext );
    
    CGRect r = CGRectMake(50.0, self.bounds.size.height-50.0-50.0, 50.0, 50.0);//self.bounds;
    //UIImage* image = [UIImage imageWithCGImage:cgImage];
	
    //画像描画
    //[image drawInRect:r];
    //状態保存
    CGContextSaveGState(context);
    
    CGContextScaleCTM(context, 1, -1);
	CGContextTranslateCTM(context, 0, -self.bounds.size.height);
    
    CGContextDrawImage(context, r,cgImage) ;
    
    //戻す
    CGContextRestoreGState(context);

    
    //カラー作成
    CGColorRef color = CGColorCreate(space,col);
    //色空間の解放
    CGColorSpaceRelease(space);
    
    CGContextSetFillColorWithColor(context,color);
	
    //弧の位置
	CGPoint				theLocation = CGPointMake(200.0, 200.0);
    
	//弧をパスに加える
	CGContextAddArc(context, theLocation.x, theLocation.y, 100, radians(0), radians(270), 0);

    //塗り
	CGContextFillPath(context);
    
    //弧をパスに加える
	CGContextAddArc(context, 100, 100, 20, radians(0), radians(270), 0);
    
    float col2[4];
    col2[0] = 1.0;
    col2[1] = 0.5;
    col2[2] = 0.5;
    col2[3] = 0.5;
    CGColorRef color2 = CGColorCreate(space,col2);
    CGContextSetFillColorWithColor(context,color2);

    //塗り
	CGContextFillPath(context);
    
    
    //カラーの解放
    CGColorRelease(color);