2015-02-23 21 views
0

拍攝的圖像我有一個包含WebCamTexture和一個按鈕來捕捉圖像 enter image description here修改unity3d

腳本來捕捉圖像

void CaptureAndSave() { 
    Debug.Log (Camera_panel_script.webCameraTexture); 
    Texture2D snap = new Texture2D(Camera_panel_script.webCameraTexture.width, Camera_panel_script.webCameraTexture.height); 
    snap.SetPixels(Camera_panel_script.webCameraTexture.GetPixels()); 
    snap.Apply(); 
    Debug.Log (Application.persistentDataPath.ToString()); 
    System.IO.File.WriteAllBytes(
     Application.persistentDataPath+"/my_image.png", 
     snap.EncodeToPNG() 
     ); 
} 

enter image description here

這是一個平面結果圖像

我該如何修改我的代碼才能添加the image標識到我的結果圖片?因此所拍攝的圖像是這樣的:

enter image description here

回答

0

如果你有Unity Pro中,一個方法是在那個只呈現它上面的捕捉圖像,並進入一個方式輔助相機設置RenderTexture,然後保存RenderTexture。然而,對於RenderTextures,你需要有Pro。

,你可以在統一免費做這一點的方法是複製從圖像unsing GetPixel(http://docs.unity3d.com/ScriptReference/Texture2D.GetPixel.html)每個像素,並把每個像素在正確的位置捕獲的圖像與SetPixel(http://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html)。

但這很慢。您需要在上圖中的每個像素上循環,並將其置於目標圖像上的正確位置。並且,運行Texture2D.Apply();

+0

是否有任何現場演示示例,我可以看到? – Sora 2015-02-24 07:25:34

+0

可以給我看一個例子嗎? – Sora 2015-02-24 19:52:18

+0

@Sora嗨,我沒有準備好一個示例。你有什麼困難?你有沒有嘗試改變個別像素?您是否嘗試將每個像素更改爲隨機顏色?這些練習可以幫助你理解函數的使用。如果是邏輯,則認爲您必須從徽標中讀取像素,然後將其放入捕獲的圖像中,以X和Y偏移量,然後應用到紋理以查看更改。希望能幫助到你。 – jbernardo 2015-02-25 19:17:46