Fork me on GitHub

绘制到CGImageRef

http://bbs.51cto.com/thread-842406-1-1.html

#define HIRESDEVICE (((int)rintf([[[UIScreen mainScreen] currentMode] size].width/[[UIScreen mainScreen] bounds].size.width )>1))



- (CGImageRef) blerg

    {

    CGFloat imageScale = (CGFloat)1.0;

    CGFloat width = (CGFloat)180.0;

    CGFloat height = (CGFloat)180.0;



    if ( HIRESDEVICE )

        {

        imageScale = (CGFloat)2.0;

        }



    // Create a bitmap graphics context of the given size

    //

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(NULL, width * imageScale, height * imageScale, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);


    // Draw ...

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

    // …

    // Get your image

    CGImageRef cgImage = CGBitmapContextCreateImage(context);

    CGColorSpaceRelease(colorSpace);

    CGContextRelease(context);

    return cgImage;

    }

posted on 2012-04-23 18:53  pengyingh  阅读(954)  评论(0)    收藏  举报

导航