GLPaint save image

后端 未结 5 1263
南笙
南笙 2021-01-31 23:39

I\'m trying to develop a complex painting application on the iPhone. I\'m currently drawing using Quartz (e.g. CGContext...). Unfortunately the Quartz overhead is

5条回答
  •  礼貌的吻别
    2021-02-01 00:30

    void SaveScreenImage()
    
    {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    CGImageRef cgImage = UIGetScreenImage();
    void *imageBytes = NULL;
    if (cgImage == NULL) {
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    imageBytes = malloc(320 * 480 * 4);
    CGContextRef context = CGBitmapContextCreate(imageBytes, 320, 480, 8, 320 * 4, colorspace, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big);
        CGColorSpaceRelease(colorspace);
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
            CGRect bounds = [window bounds];
            CALayer *layer = [window layer];
            CGContextSaveGState(context);
            if ([layer contentsAreFlipped]) {
                CGContextTranslateCTM(context, 0.0f, bounds.size.height);
                CGContextScaleCTM(context, 1.0f, -1.0f);
            }
    [layer renderInContext:(CGContextRef)context];
            CGContextRestoreGState(context);
        }
        cgImage = CGBitmapContextCreateImage(context);
        CGContextRelease(context);
    }
    UIImage *image=[UIImage imageWithCGImage:cgImage];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); 
    [pool release];
    }
    

    This code will save as you see on the screen.But it maybe private api.

提交回复
热议问题