2017-03-09 48 views
0

我是Unity新手。我正在嘗試製作一個代碼,它將在scrollview中獲取對象的屏幕截圖。我的問題是,scrollView內的整個對象/圖像在設備中不可見。您必須平移scrollView才能看到隱藏的部分。我想要做的是在scrollview中截取整個對象/圖像的屏幕截圖。請幫助統一:在scrollView內容拍屏幕時遇到問題

我下面的代碼是

private IEnumerator TakeScreenshot() 
    { 
    yield return new WaitForEndOfFrame(); 

    var width = Screen.width; 
    var height = Screen.height; 
    var tex = new Texture2D(width, height, TextureFormat.RGB24, false); 
    // Read screen contents into the texture 
    tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); 
    tex.Apply(); 
    byte[] screenshot = tex.EncodeToPNG(); 
} 

以上代碼只需要截圖是在設備屏幕上。我想截取整個對象/圖像的截圖。請幫助

回答

0

只需指向具有渲染紋理設置朝向對象的攝像頭並使用編碼功能即可。

建議使用渲染紋理和encodeToPng

您的代碼只是創建一個紋理並讀取其中的第一個像素,並且不會執行任何操作。