티스토리 뷰
//화면 캡쳐해서 저장하기
CGRect screenRect = CGRectMake(0, 40, 480, 320);
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextClipToRect(context, screenRect);
[self.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); // 사진앨범 저장
UIGraphicsEndImageContext();
//선그리기
-(id)init
{
if (self =[super init])
{
drawImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
drawImgView.backgroundColor = [UIColor darkGrayColor];
[self.view addSubview:drawImgView];
[drawImgView release];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
startX = [touch locationInView:drawImgView].x;
startY = [touch locationInView:drawImgView].y;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
int moveX = [touch locationInView:drawImgView].x;
int moveY = [touch locationInView:drawImgView].y;
UIGraphicsBeginImageContext(drawImgView.frame.size);
[drawImgView.image drawInRect:CGRectMake(0, 0, drawImgView.frame.size.width, drawImgView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startX, startY);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), moveX, moveY);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImgView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
startX = moveX;
startY = moveY;
}
'iOS > 자료정리' 카테고리의 다른 글
iSO6 StoryBoard 사용시 특정 뷰만 화면 회전 시키기. (0) | 2013.07.17 |
---|---|
NSXMLParser 에러 내용 (0) | 2013.03.11 |
iOS SNS WebView 연동 관련 정리 (0) | 2012.11.04 |
[iPhone]UIButton (0) | 2012.10.23 |
[iPhone]UIImageView (0) | 2012.05.10 |