u3d吧 关注:4,713贴子:7,942
  • 0回复贴,共1

请教各位大神拍照问题

只看楼主收藏回复

拍照实现的代码:
/// <summary>
/// 捕获窗口位置
/// </summary>
public IEnumerator start()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
WebCamDevice[] devices = WebCamTexture.devices;
deviceName = devices[0].name;
tex = new WebCamTexture(deviceName, Screen.width, Screen.height, 15);
tex.Play();
}
}
/// <summary>
/// 获取截图
/// </summary>
/// <returns>The texture.</returns>
public IEnumerator getTexture()
{
yield return new WaitForEndOfFrame();
Texture2D t = new Texture2D(Screen.width , Screen.height);
t.SetPixels(tex.GetPixels());
//t.ReadPixels(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 50, 360, 300), 0, 0, false);
//距X左的距离 距Y屏上的距离
// t.ReadPixels(new Rect(220, 180, 200, 180), 0, 0, false);
t.Apply();
byte[] byt = t.EncodeToPNG();
string path = "/mnt/sdcard/ehero/Photoes/";
if (Directory.Exists(path)==false)
{
Directory.CreateDirectory(path);//创建新路径
}
File.WriteAllBytes(path + DateTime.Now.ToString("YYMMDDmmss") + ".jpg", byt);
tex.Play();
}
在红米上测试的结果是横屏的图片没问题,竖屏的就有问题。求大神指导一下解决问题办法。


IP属地:广东1楼2015-06-04 11:09回复