目前我正在使用 glreadpixels() 捕获屏幕。捕获的图像通常是镜像图像,因此我将图像翻转回正常。现在我想将捕获的数据(图像)旋转 90 度。知道该怎么做吗?
我用来捕获屏幕数据的代码是:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
int backingWidth = screenBounds.size.width;
int backingHeight =screenBounds.size.height;
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
NSInteger myDataLength = backingWidth * backingHeight * 4;
GLuint *buffer;
if((buffer= (GLuint *) malloc(myDataLength)) == NULL )
NSLog(@"error initializing the buffer");
glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// code for flipping back (mirroring the image data)
for(int y = 0; y < backingHeight / 2; y++) {
for(int xt = 0; xt < backingWidth; xt++) {
GLuint top = buffer[y * backingWidth + xt];
GLuint bottom = buffer[(backingHeight - 1 - y) * backingWidth + xt];
buffer[(backingHeight - 1 - y) * backingWidth + xt] = top;
buffer[y * backingWidth + xt] = bottom;
}
}
知道如何将缓冲区中捕获的数据旋转 90 度吗?谢谢