UIView内で線を描く方法を簡単に説明する。


線を引く

UIBezierPathを用いる

  1. UIBezierPath取得
  2. 色や太さを指定
  3. 始点設定
  4. 終点指定、直線を設定
  5. パスを閉じる
  6. 描画する
以下をdrawRect内で

UIBezierPath *aPath = [UIBezierPath bezierPath];
[[UIColorblackColor] setStroke];
aPath.lineWidth = 1;
[aPath moveToPoint:CGPointMake(0, 0)];
[aPath addLineToPoint:CGPointMake(100, 100)];
[aPath closePath];
[aPath stroke];

CGImageRef

UIImageから作る。
[[image CGImage];

情報の取得

  1. CGImageGetWidth(imageRef);
  2. CGImageGetHeight(imageRef);
  3. CGImageGetBitsPerComponent(imageRef);
  4. CGImageGetBitsPerPixel(imageRef);
  5. CGImageGetBytesPerRow(imageRef);
返り値はsize_t

拡大縮小

UIGraphicsBeginImageContext(newSize);
drawInRect:CGRectMake(0, 0, newSize.width, newSize.hright)];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageを作る

UIImage *newImage = [[UIImage alloc] initWithCGImage:ref];

お絵描き系アプリ作成 UIPenGestureRecognizer


最終更新:2012年11月30日 09:12