Sparrow-Framework: захват экрана SPView (iOS)

Я нашел эту ссылку в другом вопросе StackOverflow: http://reusablesnippets.posterous.com/capture-uiview

В нем подробно описано использование UIGraphicsBeginImageContext() для захвата содержимого экрана. Я нахожусь в проекте фреймворка Sparrow, и мой SPView просто возвращает черный прямоугольник. Нельзя ли захватить SPView (подкласс UIView)?


person Justin    schedule 01.02.2011    source источник


Ответы (1)


Я не знаю, получили ли вы ответ где-то еще, но я написал небольшой метод, чтобы сделать это некоторое время назад. http://iky1e.tumblr.com/post/3054935938/save-opengl-content-to-photolibrary

-(void)saveRectangle:(SPRectangle*)rectangle{
        int bufferLenght = (rectangle.width*(rectangle.height+30)*4);

        int myWidth = rectangle.width;
        int myHeight = rectangle.height;
        int myY = self.stage.height-rectangle.y-rectangle.height;
        int myX = rectangle.x;

        unsigned char buffer[bufferLenght];
        glReadPixels(myX, myY, myWidth, myHeight, GL_RGBA, GL_UNSIGNED_BYTE, &buffer);

        CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, &buffer, bufferLenght, NULL);
        CGImageRef iref = CGImageCreate(myWidth,myHeight,8,32,myWidth*4,CGColorSpaceCreateDeviceRGB(),
                                                                        kCGBitmapByteOrderDefault,ref,NULL, true, kCGRenderingIntentDefault);
        uint32_t* pixels = (uint32_t *)malloc(bufferLenght);
        CGContextRef context = CGBitmapContextCreate(pixels, myWidth, myHeight, 8, myWidth*4, CGImageGetColorSpace(iref),
                                                                                                 kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big);
        CGContextTranslateCTM(context, 0.0, myHeight);
        CGContextScaleCTM(context, 1.0, -1.0);
        CGContextDrawImage(context, CGRectMake(0.0, 0.0, myWidth, myHeight), iref);
        CGImageRef outputRef = CGBitmapContextCreateImage(context);
        UIImage *image = [[UIImage alloc] initWithCGImage:outputRef];
        free(pixels);

        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        [image release];
}
person Kyle Howells    schedule 01.04.2011