아이폰어플개발정보2010. 6. 24. 11:38
UIImage에서 그림 그리는 방법

by alex 4. 5월 2009 13:15
-(UIImage *)addCircle:(UIImage *)img radius:(CGFloat)radius latCon:(CGFloat)lat lonCon:(CGFloat)lon{

    int w = img.size.width;

    int h = img.size.height;

    lon = h - lon;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

   
 //draw the circle

 CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);

 CGRect leftOval = {lat- radius/2, lon - radius/2, radius, radius};

 CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 0.3);

 CGContextAddEllipseInRect(context, leftOval);

 CGContextFillPath(context);

 
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);

    CGContextRelease(context);

    CGColorSpaceRelease(colorSpace);

 
    return [UIImage imageWithCGImage:imageMasked];

}



출처 : http://blog.naver.com/PostView.nhn?blogId=amoros21&logNo=140107111276
Posted by 오늘마감

댓글을 달아 주세요