1
写真を撮影し、記念碑などの異なる背景を置くプログラムを作成しようとしています。これまでのところ、私はそれは常にすべての黒終わるので、私はスクリーンショットや写真を取ることができない、私は写真をユニティで撮る#
webcamTexture = new WebCamTexture();
rawImage.texture = webcamTexture;
rawImage.material.mainTexture = webcamTexture;
webcamTexture.Play();
Texture2D PhotoTaken = new Texture2D (webcamTexture.width, webcamTexture.height);
PhotoTaken.SetPixels (webcamTexture.GetPixels());
PhotoTaken.Apply();
しかし、このコードでプロジェクトを開始するときに、カメラを向けることができました。私は別のコードを試しましたが、何も動作していません。誰かが助けてくれますか?おかげで、いくつかの試行後
EDIT
が、これは私が持っているコードです:
WebCamTexture webcamTexture;
public RawImage rawImage;
void Start() {
webcamTexture = new WebCamTexture();
rawImage.texture = webcamTexture;
rawImage.material.mainTexture = webcamTexture;
webcamTexture.Play();
RenderTexture texture= new RenderTexture(webcamTexture.width, webcamTexture.height,0);
Graphics.Blit(webcamTexture, texture);
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(OnClick);
}
public IEnumerator Coroutine(){
yield return new WaitForEndOfFrame();
}
public void OnClick() {
var width = 767;
var height = 575;
Texture2D texture = new Texture2D(width, height);
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
texture.Apply();
// Encode texture into PNG
var bytes = texture.EncodeToPNG();
//Destroy(texture);
File.WriteAllBytes (Application.dataPath + "/../SavedScreen.png", bytes);
}
とスクリーンショットが撮影されたこの次のコードで、それは全部の写真をとり、そしてません画面のちょうど少し。あなたは、画面の特定の部分にスクリーンショットを取るためにUnity
Application.CaptureScreenshot("Screenshot.png");
EDIT 1
に、このようなスクリーンショットを撮ることができ
void Start()
{
// Set the playback framerate!
// (real time doesn't influence time anymore)
Time.captureFramerate = frameRate;
// Find a folder that doesn't exist yet by appending numbers!
realFolder = folder;
int count = 1;
while (System.IO.Directory.Exists(realFolder))
{
realFolder = folder + count;
count++;
}
// Create the folder
System.IO.Directory.CreateDirectory(realFolder);
}
void Update()
{
// name is "realFolder/shot 0005.png"
var name = string.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount);
// Capture the screenshot
Application.CaptureScreenshot(name, sizeMultiplier);
}
}
私は画面全体のスクリーンショットに表示したくない場合は?ちょうど1つの部分 – Dmgm
私が本当にばかばかしいように見えたら私はすみませますが、私は本当にこれに新しいです。しかし、それは動作しません。 Rectの部分にエラーがあり、たくさんのOSが試行した後、私は何をすべきか分からない。 – Dmgm
質問を試したコードで更新できますか? – Hristo