Unity 根据 ugui某张图片大小的尺寸截图计算,
注意点:根据ugui image尺寸计算出屏幕所占尺寸 ,需要注意 用CanvasScaler 来计算缩放数值
public CanvasScaler canvasScaler;//canvas 的 CanvasScaler 获取 referenceResolution
private IEnumerator ScreenShot(){
yield return new WaitForEndOfFrame();
float localScaleX = Screen.width / canvasScaler.referenceResolution.x;//适配;
float localScaleY = Screen.height / canvasScaler.referenceResolution.y;//适配;
float localScale = localScaleX<localScaleY?localScaleX:localScaleY;
int width = (int)(bg.rect.width * localScale);
int height = (int)(bg.rect.height * localScale);
int beginx = (int)((Screen.width - width) * 0.5f + bg.anchoredPosition.x * localScale);
int beginy = (int)((Screen.height - height) * 0.5f + bg.anchoredPosition.y * localScale);