private Texture2D captureTex;
private byte[] captureBytes;
private Rect captureRect;
IEnumerator CutImage()
{
captureTex = new Texture2D(Screen.width, (int)captureRect.height, TextureFormat.RGB24, true);
yield return new WaitForEndOfFrame();
captureTex.ReadPixels(new Rect(0, 170, captureRect.width, captureRect.height), 0, 0, true);
captureTex.Apply();
yield return captureTex;
captureBytes = captureTex.EncodeToPNG();
//File.WriteAllBytes(Configuration.PHOTO_PATH + "test.png", captureBytes);
}
注释:
new Texture2D 决定最终生成的PNG图片的尺寸和格式等信息
void ReadPixels(Rect source, int destX, int destY, [DefaultValue("true")] bool recalculateMipMaps);
参数:
source:屏幕截取起点的X坐标,屏幕截取起点的Y坐标,屏幕截取的宽度,屏幕截取的高度
destX:? ? 截取到的纹理在PNG图片内相对于左下角坐标原点的X轴偏移量
destY:? ? 截取到的纹理在PNG图片内相对于左下角坐标原点的Y轴偏移量
最后一个不清楚。
|