详解SDL_RenderCopyEx函数

/**
 *  \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手机,画的不好,全靠想象力啦~~~~)

android手机分辨率,坐标系

 

2.竖屏中,按照比例显示了一张YUV视频,或者一副jpg图片,此时的画面位置就是srcrect参数(sx,sy,sw,sh)

竖屏居中显示

 

3.dstrect将是成功的关键。dstrect是图像尚未旋转时的rect坐标(dx,dy,dpw,dph),可以看出来,此时的dx已经在手机屏幕的左边,即负数坐标值;dpw也大于手机屏幕实际的大小,整个画面已经超出了屏幕,如果不做flip旋转,就只能看到放大后的一部分图像,示意图如下

dstrect,旋转前的画面

 

4.filp旋转90度以后,变成最终的效果图

旋转后的效果图

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值