Xcode 8.0が登場しました。 旧プロジェクトをXcode 8.0で開くと、Swift 3.0(あるいはSwift 2.4)に変換するよう促すダイアログが出現しました。 CoreGraphicsコードをSwift 3.0への自動コンバートにかけたところ、変換されない部分が残りました。 let pathRef = CGMutablePath() CGPathMoveToPoint(pathRef, nil, 20, 0) CGPathAddLineToPoint(pathRef, nil, 200, 0) CGPathAddCurveToPoint(pathRef, nil, 205.523, 0, 210, 4.435, 210, 10) CGPathAddLineToPoint(pathRef, nil, 210, 122) CGPathAddCurveToPoint(pathRef
Extension 今回は UIImage の Extension として実装します。 Objective-C で言えばカテゴリです。 サンプルコード import UIKit extension UIImage { class func colorImage(color: UIColor, size: CGSize) -> UIImage { UIGraphicsBeginImageContext(size) let rect = CGRect(origin: CGPointZero, size: size) let context = UIGraphicsGetCurrentContext() CGContextSetFillColorWithColor(context, color.CGColor) CGContextFillRect(context, rect) let image
画像描画関連のまとめ CGContextを使って画像描画 雰囲気としては、JavaScriptのCanvasを使ったことがある人であれば、あのイメージです。 画像を加工するフローとしては以下。 CGContextのサイズを決めて開く CGContextを取得 (必要であれば)CGContextのtransformを設定 Draw/Render系メソッドを使ってCGContextに画像を描画 CGContextから描画済の画像を取得 CGContextを閉じる サンプルコード //コンテキストを開く CGSize size = [描画したい画像サイズ]; UIGraphicsBeginImageContext(size); //コンテキストを得る CGContextRef context = UIGraphicsGetCurrentContext(); //コンテキストの状態を保存 CGCo
SwiftでCoreGraphicsによる画像を作成。 CoreGraphicsは、UIImageViewやUIImageなどの既存の画像を使った処理ではなく、オリジナルの図形などを描画したいときに利用することができる、フレームワークです。 UIImageなどでは、xxx.jpgなどのファイルを画像を表示したり、拡大、回転などできますが、これらの画像を合成したり、切り抜いたりする際に活用できると便利です。 直接UIViewに画像書き込んだり、本来はいろいろな使い方があるのですが、ここではCoreGraphicsで描画した画像を、UIImageとしてアプリから利用するという考え方だけに絞って確認します。 CoreGraphicsによる描画の基本手順 ここでは、UIImageの変数にCoreGraphicsで描画した画像を代入するまでの手順を考えます。 グラフィックスコンテキストの作成 描画の
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く