2017-04-07 8 views
1

사진을 찍어 기념비 같은 다른 배경으로 배치하는 프로그램을 만들려고합니다. 지금까지, 나는 항상 모든 검은 끝 때문에 스크린 샷 또는 사진을 찍을 수 없다, 내가화음으로 사진 찍기 C#

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(); 

그러나이 코드로 프로젝트를 시작할 때 카메라를 회전 할 수 있었다. 다른 코드를 시도했지만 아무 것도 작동하지 않습니다. 누군가 제발 도와 줄 수 있니? 일부 시도 후 감사

편집

, 이것은 내가 가지고있는 코드 :

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"); 

Reference

EDIT 1
이 같은 화면을 캡처 할 수

답변

2

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); 
} 

}는 화면의 특정 부분에 화면을 캡처하려면 다음 스크립트를 사용하십시오.

var width = 400; 
var height = 300; 
var startX = 200; 
var startY = 100; 
var tex = new Texture2D (width, height, TextureFormat.RGB24, false); 

tex.ReadPixels (Rect(startX, startY, width, height), 0, 0); 
tex.Apply(); 

// Encode texture into PNG 
var bytes = tex.EncodeToPNG(); 
Destroy(tex); 

File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes); 

Reference

+0

내가 전체 화면의 스크린 샷에 표시하지 않으려면? 한 부분 만 – Dmgm

+0

정말 바보 같아서 미안하지만, 정말이에요. 그러나 그것은 효과가 없습니다. Rect 부분에 오류가 있으며 많은 os가 시도한 후에 무엇을해야할지 모르겠습니다. – Dmgm

+1

시도한 코드로 질문을 업데이트 할 수 있습니까? – Hristo