Drawing into CGImageRef

前端 未结 1 1143
一向
一向 2020-12-31 20:34

I want to create a CGImageRef and draw points to it.

What context to use to create an empty CGImageRef and be able to draw onto it. CGContextRef or CGBitmapContextRe

相关标签:
1条回答
  • #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;
        }
    
    0 讨论(0)
提交回复
热议问题