在unity3d中修改捕获的图像

Modify a captured image in unity3d

我有一个平面,其中包含一个 WebCamTexture 和一个用于捕获图像的按钮

捕获图像的脚本

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

这是结果图像

我如何修改我的代码以将 the image 徽标添加到我的结果图片中?所以捕获的图像看起来像这样:

如果您有 Unity Pro,一种方法是将辅助相机设置为仅将捕获的图像及其上方的图像渲染到 RenderTexture 中,然后保存该 RenderTexture。但是,对于 RenderTextures,您需要 Pro。

您可以在 Unity Free 中执行此操作的一种方法是不使用 GetPixel (http://docs.unity3d.com/ScriptReference/Texture2D.GetPixel.html) and putting each pixel in the correct position on your captured image with SetPixel (http://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html) 从图像中复制每个像素。

但是,这很慢。您需要循环遍历上图中的每个像素并将其放在目标图像上的正确位置。还有,运行 Texture2D.Apply();