Отсутствует часть изображения при съемке скриншота при поддержке Retina Display - PullRequest
1 голос
/ 27 марта 2012

В настоящее время я работаю над включением поддержки отображения сетчатки для моей игры. В игре у нас есть функция, которую пользователь может делать скриншот. Мы используем эту часть кода, которую нашли недавно в сети, и она отлично работает, когда мы не поддерживаем отображение сетчатки:

CCDirector* director = [CCDirector sharedDirector];
CGSize size = [director winSizeInPixels];

//Create buffer for pixels
GLuint bufferLength = size.width * size.height * 4;
GLubyte* buffer = (GLubyte*)malloc(bufferLength);

//Read Pixels from OpenGL
glReadPixels(0, 100, size.width, size.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
//Make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, bufferLength, NULL);

//Configure image
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * size.width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef iref = CGImageCreate(size.width, size.height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);

uint32_t* pixels = (uint32_t*)malloc(bufferLength);
CGContextRef context = CGBitmapContextCreate(pixels, size.width, size.height, 8, size.width * 4, CGImageGetColorSpace(iref), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGContextTranslateCTM(context, 0, size.height);
CGContextScaleCTM(context, 1.0f, -1.0f);

switch (director.deviceOrientation)
{
    case CCDeviceOrientationPortrait:
        break;
    case CCDeviceOrientationPortraitUpsideDown:
        CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(180));
        CGContextTranslateCTM(context, -size.width, -size.height);
        break;
    case CCDeviceOrientationLandscapeLeft:
        CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(-90));
        CGContextTranslateCTM(context, -size.width, 0);
        break;
    case CCDeviceOrientationLandscapeRight:
        CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(90));
        CGContextTranslateCTM(context, size.width * 0.5f, -size.height);
        break;
}

CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), iref);
UIImage *outputImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];

//Dealloc
CGDataProviderRelease(provider);
CGImageRelease(iref);
CGContextRelease(context);
free(buffer);
free(pixels);

return outputImage;

Но когда мы включили отображение сетчатки в кокосах 0.99.5. Эта функциональность немного испорчена, так как она пропустит небольшую левую часть изображения, в то время как высота все еще верна. Так что мне интересно, если что-то не так с кодом или я что-то здесь не так делаю?

Заранее спасибо за любой ответ!

...