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拍摄的完整四张图片,那么如何比较像素颜色值? –