需求,在横版的情况下,截取屏幕要求为竖屏
我的实现方法
修改ccUtils.cpp onCaptureScreen 在pack了纹理像素之后,将纹理像素单元重新排列,具体如下
//测试修改之后的-----主要思路是将纹理横向分割,从下往上读取依次重新排列对齐放置到flippedBuffer,然后使用flippedBuffer数组生成图片
for (int col = 0; col < width; col++)
{
for (int row = 0; row < height; ++row)
{
*(flippedBuffer.get() + (width - col - 1) * height * 4 + row) = *(buffer.get() + (height - row - 1) * width * 4 + col);
*(flippedBuffer.get() + (width - col - 1) * height * 4 + row + 1) = *(buffer.get() + (height - row - 1) * width * 4 + col + 1);
*(flippedBuffer.get() + (width - col - 1) * height * 4 + row + 2) = *(buffer.get() + (height - row - 1) * width * 4 + col + 2);
*(flippedBuffer.get() + (width - col - 1) * height * 4 + row + 3) = *(buffer.get() + (height - row - 1) * width * 4 + col + 3);
}
}
/*for (int row = 0; row < height; ++row) // 原版
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}*/
image->initWithRawData(flippedBuffer.get(), width * height * 4, width,height, 8);
将图片生成宽高位置坐交换
image->initWithRawData(flippedBuffer.get(), width * height * 4, height, width, 8);
屏幕场景是这样的
操作之后生成的图片效果如下
没有达到想要的目的,我这种思路是错误的?望高手请教


