/**
* \brief Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center
*
* \param renderer The renderer which should copy parts of a texture.
* \param texture The source texture.
* \param srcrect A pointer to the source rectangle, or NULL for the entire
* texture.
* \param dstrect A pointer to the destination rectangle, or NULL for the
* entire rendering target.
* \param angle An angle in degrees that indicates the rotation that will be applied to dstrect
* \param center A pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around dstrect.w/2, dstrect.h/2).
* \param flip An SDL_RendererFlip value stating which flipping actions should be performed on the texture
*
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderCopyEx(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect,
const double angle,
const SDL_Point *center,
const SDL_RendererFlip flip);
中文翻译
/**
* \ 简要:将源纹理的一部分复制到当前渲染目标,围绕给定中心旋转角度
*
* \ 参数 renderer:应该复制纹理部分的渲染器。
* \ 参数 texture:源纹理。
* \ 参数 srcrect:指向源矩形的指针,或整个NULL
*质地。
* \ 参数 dstrect:指向目标矩形的指针,或者为NULL
*整个渲染目标。
* \ 参数 angle:以度为单位的角度,表示将应用于dstrect的旋转
* \ 参数 center:指向指示dstrect将围绕其旋转的点的点的指针(如果为NULL,则将围绕dstrect.w / 2,dstrect.h / 2进行旋转)。
* \ 参数 flip:一个SDL_RendererFlip值,说明应该对纹理执行哪些翻转操作
*
* \成功时返回0,或者出错时返回-1
*/
如果做android手机视频旋转时,会发现srcrect,dstrect,center,flip这4个参数,并没有那么容易掌控,稍不留神,就会入坑。
总体而言,4个参数的使用顺序是srcrect->dstrect->center->flip。
问题来源:
如果我们要将一个居中显示的yuv的竖屏画面,旋转90度,变成横屏居中显示的画面,该如何设置srcrect,dstrect,center这3个参数?
问题解决:
1.首先,一台android手机,它在物理上的分辨率肯定是固定的,比如dh=1920,dw=1080(以下是一部价值千元的android手机,画的不好,全靠想象力啦~~~~)
2.竖屏中,按照比例显示了一张YUV视频,或者一副jpg图片,此时的画面位置就是srcrect参数(sx,sy,sw,sh)
3.dstrect将是成功的关键。dstrect是图像尚未旋转时的rect坐标(dx,dy,dpw,dph),可以看出来,此时的dx已经在手机屏幕的左边,即负数坐标值;dpw也大于手机屏幕实际的大小,整个画面已经超出了屏幕,如果不做flip旋转,就只能看到放大后的一部分图像,示意图如下
4.filp旋转90度以后,变成最终的效果图