0
是否可以根據所需的形狀裁剪捕獲的圖像?我使用原始圖像+網絡攝像頭紋理來激活相機並保存圖像。並且我使用UI圖像疊加方法作爲掩碼來覆蓋不需要的部分。我將在後半部分將圖片附加到char模型中。對不起,我是新來的團結。感謝您的幫助!如何裁剪捕獲的圖像? --C#
下面是我在我的代碼:
// start cam
void Start() {
devices = WebCamTexture.devices;
background = GetComponent<RawImage>();
devCam = new WebCamTexture();
background.texture = devCam;
devCam.deviceName = devices [0].name;
devCam.Play();
}
void OnGUI()
{
GUI.skin = skin;
//swap front and back camera
if (GUI.Button (new Rect ((Screen.width/2) - 1200, Screen.height - 650, 250, 250),"", GUI.skin.GetStyle("btn1"))) {
devCam.Stop();
devCam.deviceName = (devCam.deviceName == devices[0].name) ? devices[1].name : devices[0].name;
devCam.Play();
}
//snap picture
if (GUI.Button (new Rect ((Screen.width/2) - 1200, Screen.height - 350, 250, 250), "", GUI.skin.GetStyle ("btn2"))) {
OnSelectCapture();
//freeze cam here?
}
}
public void OnSelectCapture()
{
imgID++;
string fileName = imgID.ToString() + ".png";
Texture2D snap = new Texture2D (devCam.width, devCam.height);
Color[] c;
c = devCam.GetPixels();
snap.SetPixels (c);
snap.Apply();
// Save created Texture2D (snap) into disk as .png
System.IO.File.WriteAllBytes (Application.persistentDataPath +"/"+ fileName, snap.EncodeToPNG());
}
}
傻我!對不起,我已經更新了與該主題相關的問題。 –
我已經更新了我的答案,並提供了有關如何繼續的說明。你應該能夠找到現有的一些例子,說明如何使用一些谷歌搜索的具體細節,但如果你卡住了,我會看看我是否可以編碼起點。 –
但我在我的設備存儲器中是使用沒有藍色背景的webcamtexture拍攝的完整四張圖片,那麼如何比較像素顏色值? –