本文整理汇总了C#中UnityEngine.Camera.Render方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.Render方法的具体用法?C# Camera.Render怎么用?C# Camera.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Camera
的用法示例。
在下文中一共展示了Camera.Render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SnapShot
static void SnapShot(Camera cam, string path)
{
cam.Render();
cam.Render();
Texture2D image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height, TextureFormat.RGB24, false);
image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
image.Apply();
var bytes = image.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
}
示例2: CaptureCamera
/// <summary>
/// 对相机截图。
/// </summary>
/// <returns>The screenshot2.</returns>
/// <param name="camera">Camera.要被截屏的相机</param>
/// <param name="rect">Rect.截屏的区域</param>
Texture2D CaptureCamera(Camera camera, Rect rect)
{
// 创建一个RenderTexture对象
Debug.Log(rect.width + " " + rect.height);
RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
// 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
camera.targetTexture = rt;
camera.Render();
//--- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
//camera2.targetTexture = rt;
//camera2.Render();
//-------------------------------------------------------------------
// 激活这个rt, 并从中中读取像素。
RenderTexture.active = rt;
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
screenShot.Apply();
// 重置相关参数,以使用camera继续在屏幕上显示
camera.targetTexture = null;
//ps: camera2.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
GameObject.Destroy(rt);
CacheFactory.SaveToPicture(screenShot, "/ScreenShot.png",CacheFactory.PictureType.JPG);
return screenShot;
}
示例3: CaptureByCamera
IEnumerator CaptureByCamera(Camera mCamera, Rect mRect, string mFileName)
{
yield return new WaitForEndOfFrame ();
//初始化RenderTexture
RenderTexture mRender = new RenderTexture ((int)mRect.width, (int)mRect.height, 0);
//设置相机的渲染目标
mCamera.targetTexture = mRender;
//开始渲染
mCamera.Render ();
//激活渲染贴图读取信息
RenderTexture.active = mRender;
Texture2D mTexture = new Texture2D ((int)mRect.width, (int)mRect.height, TextureFormat.RGB24, false);
//读取屏幕像素信息并存储为纹理数据
mTexture.ReadPixels (mRect, 0, 0);
//应用
mTexture.Apply ();
//释放相机,销毁渲染贴图
mCamera.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy (mRender);
//将图片信息编码为字节信息
byte[] bytes = mTexture.EncodeToPNG ();
//保存
System.IO.File.WriteAllBytes (mFileName, bytes);
}
示例4: Capture
Texture2D Capture(Camera camera, Rect rect)
{
// 创建一个RenderTexture对象
RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
// 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
camera.targetTexture = rt;
camera.Render();
//ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
//ps: camera2.targetTexture = rt;
//ps: camera2.Render();
//ps: -------------------------------------------------------------------
// 激活这个rt, 并从中中读取像素。
RenderTexture.active = rt;
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);
screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
screenShot.Apply();
// 重置相关参数,以使用camera继续在屏幕上显示
camera.targetTexture = null;
//ps: camera2.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
GameObject.Destroy(rt);
// 最后将这些纹理数据,成一个png图片文件
byte[] bytes = screenShot.EncodeToPNG();
string filename = Application.dataPath + "/Screenshot.png";
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("截屏了一张照片: {0}", filename));
return screenShot;
}
示例5: RTImage
Texture2D RTImage(Camera cam) {
RenderTexture currentRT = RenderTexture.active;
RenderTexture.active = cam.targetTexture;
cam.Render();
Texture2D image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height);
image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
image.Apply();
RenderTexture.active = currentRT;
return image;
}
示例6: CaptureImage
/*Source: http://raypendergraph.wikidot.com/codesnippet:capturing-a-camera-image-in-unity*/
public Texture2D CaptureImage(Camera camera, int width, int height)
{
//Debug.Log ("Capturing");
//captured = new Texture2D (width, height);
camera.Render();
RenderTexture.active = camera.targetTexture;
captured.ReadPixels(new Rect(0,0,width,height),0,0);
captured.Apply();
RenderTexture.active = null;
return captured;
}
示例7: RTImage
Texture2D RTImage(Camera cam)
{
cam.targetTexture = RenderTexture.GetTemporary(128, 128, 16);
cam.Render();
RenderTexture currentRT = RenderTexture.active;
RenderTexture.active = cam.targetTexture;
Texture2D image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height);
image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
image.Apply();
RenderTexture.active = currentRT;
Debug.Log("Sent Image to Portrait");
return image;
}
示例8: DoRenderAtlas
public Texture2D DoRenderAtlas(GameObject gameObject, int width, int height, int padding, Rect[] rss, List<MB3_TextureCombiner.MB_TexSet> textureSetss, int indexOfTexSetToRenders, bool isNormalMap, bool fixOutOfBoundsUVs, MB3_TextureCombiner texCombiner, MB2_LogLevel LOG_LEV){
LOG_LEVEL = LOG_LEV;
textureSets = textureSetss;
indexOfTexSetToRender = indexOfTexSetToRenders;
_padding = padding;
_isNormalMap = isNormalMap;
_fixOutOfBoundsUVs = fixOutOfBoundsUVs;
combiner = texCombiner;
rs = rss;
Shader s;
if (_isNormalMap){
s = Shader.Find ("MeshBaker/NormalMapShader");
} else {
s = Shader.Find ("MeshBaker/AlbedoShader");
}
if (s == null){
Debug.LogError ("Could not find shader for RenderTexture. Try reimporting mesh baker");
return null;
}
mat = new Material(s);
_destinationTexture = new RenderTexture(width,height,24,RenderTextureFormat.ARGB32);
_destinationTexture.filterMode = FilterMode.Point;
myCamera = gameObject.GetComponent<Camera>();
myCamera.orthographic = true;
myCamera.orthographicSize = height >> 1;
myCamera.aspect = width / height;
myCamera.targetTexture = _destinationTexture;
myCamera.clearFlags = CameraClearFlags.Color;
Transform camTransform = myCamera.GetComponent<Transform>();
camTransform.localPosition = new Vector3(width/2.0f, height/2f, 3);
camTransform.localRotation = Quaternion.Euler(0, 180, 180);
_doRenderAtlas = true;
if (LOG_LEVEL >= MB2_LogLevel.debug) Debug.Log(string.Format ("Begin Camera.Render destTex w={0} h={1} camPos={2}", width, height, camTransform.localPosition));
//This triggers the OnRenderObject callback
myCamera.Render();
_doRenderAtlas = false;
MB_Utility.Destroy(mat);
MB_Utility.Destroy(_destinationTexture);
if (LOG_LEVEL >= MB2_LogLevel.debug) Debug.Log ("Finished Camera.Render ");
Texture2D tempTex = targTex;
targTex = null;
return tempTex;
}
示例9: ClearMirrorTexture
void ClearMirrorTexture(Camera Cam)
{
CameraClearFlags oldClearFlags = Cam.clearFlags;
Color oldBackgroundColor = Cam.backgroundColor;
Rect oldRect = Cam.rect;
int oldCullingMask = Cam.cullingMask;
Cam.clearFlags = CameraClearFlags.SolidColor;
Cam.backgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
Cam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
Cam.cullingMask = 0;
Cam.Render();
Cam.clearFlags = oldClearFlags;
Cam.backgroundColor = oldBackgroundColor;
Cam.rect = oldRect;
Cam.cullingMask = oldCullingMask;
}
示例10: captureCam
private byte[] captureCam( Camera cam, int w, int h )
{
var oldcullmask = cam.cullingMask;
cam.cullingMask = layerMask;
RenderTexture rt = RenderTexture.GetTemporary( w, h );
var tmp = cam.targetTexture;
cam.targetTexture = rt;
cam.Render();
RenderTexture.active = rt;
_result.ReadPixels( new Rect( 0, 0, w, h ), 0, 0, false );
cam.targetTexture = tmp;
cam.cullingMask = oldcullmask;
return _result.EncodeToPNG();
}
示例11: TakeScreenshot
public static void TakeScreenshot(Camera camera, string folderName, string prefix, string suffix, ScreenshotConfig screenshotConfig)
{
var scrTexture = new Texture2D(screenshotConfig.Width, screenshotConfig.Height, TextureFormat.RGB24, false);
var scrRenderTexture = new RenderTexture(scrTexture.width, scrTexture.height, 24);
var camRenderTexture = camera.targetTexture;
camera.targetTexture = scrRenderTexture;
camera.Render();
camera.targetTexture = camRenderTexture;
RenderTexture.active = scrRenderTexture;
scrTexture.ReadPixels(new Rect(0, 0, scrTexture.width, scrTexture.height), 0, 0);
scrTexture.Apply();
SaveTextureAsFile(scrTexture, folderName, prefix, suffix, screenshotConfig);
}
示例12: CreateRenderTexture
void CreateRenderTexture(Sprite sprite)
{
GameObject.Find("background-1").GetComponent<SpriteRenderer>().sprite = sprite;
int width = (int)GameObject.Find("background-1").GetComponent<Renderer>().bounds.size.x;
int height = (int)GameObject.Find("background-1").GetComponent<Renderer>().bounds.size.y;
Vector3 nsize = Camera.main.WorldToScreenPoint(new Vector3(width, height, 0));
nsize.x *= 2.0f;
//nsize.x *= 1.33f;
nsize.y *= 2.0f;
//nsize.y *= 1.33f;
tex = new RenderTexture((int)nsize.x, (int)nsize.y, 1);
tex.useMipMap = false;
tex.filterMode = FilterMode.Point;
tex.antiAliasing = 1;
tex.Create();
cam = GetComponent<Camera>();
float previousOrthoSize = cam.orthographicSize;
float previousAspect = cam.aspect;
RenderTexture previousRenderTexture = cam.targetTexture;
Texture2D image = new Texture2D((int)nsize.x - 50, (int)nsize.y);
cam.targetTexture = tex;
float scale = 1.0f / (cam.orthographicSize / GameObject.Find("background-1").GetComponent<Renderer>().bounds.size.y / 2.0f);
cam.orthographicSize = scale;
cam.aspect = GameObject.Find("background-1").GetComponent<Renderer>().bounds.size.x / GameObject.Find("background-1").GetComponent<Renderer>().bounds.size.y;
RenderTexture past = RenderTexture.active;
RenderTexture.active = tex;
cam.Render();
image.ReadPixels(new Rect(25, 0, (int)nsize.x - 50, (int)nsize.y), 0, 0);
image.Apply();
cam.targetTexture = previousRenderTexture;
cam.orthographicSize = previousOrthoSize;
cam.aspect = previousAspect;
RenderTexture.active = past;
tex.Release();
enhancedBackgroundImages.Add(Sprite.Create(image, new Rect(0, 0, image.width, image.height), new Vector2(0.5f, 0.5f)));
}
示例13: CaptureByCamera
private IEnumerator CaptureByCamera(Camera mCamera, Rect mRect, string mFileName)
{
yield return new WaitForEndOfFrame();
RenderTexture mRender = new RenderTexture ((int)mRect.width, (int)mRect.height, 0);
mCamera.targetTexture = mRender;
mCamera.Render ();
RenderTexture.active = mRender;
Texture2D mTexture = new Texture2D ((int)mRect.width, (int)mRect.height, TextureFormat.RGB24, false);
mTexture.ReadPixels (mRect, 0, 0);
mTexture.Apply ();
mCamera.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy (mRender);
byte [] bytes = mTexture.EncodeToPNG ();
System.IO.File.WriteAllBytes (mFileName, bytes);
}
示例14: Start
// Use this for initialization
void Start()
{
main_camera = GameObject.Find (camera_name).GetComponent<Camera> ();
if (hologram) {
render_texture = new RenderTexture (Constant.WIDTH, Constant.HEIGHT * 2, 24);
main_camera.targetTexture = render_texture;
main_camera.Render ();
RenderTexture.active = render_texture;
GameObject.Find ("triangle0").GetComponent<Renderer> ().material.mainTexture = render_texture;
GameObject.Find ("triangle1").GetComponent<Renderer> ().material.mainTexture = render_texture;
GameObject.Find ("triangle2").GetComponent<Renderer> ().material.mainTexture = render_texture;
GameObject.Find ("triangle3").GetComponent<Renderer> ().material.mainTexture = render_texture;
} else {
main_camera.depth = 0;
main_camera.transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
示例15: TakeScreenshot
private Texture2D TakeScreenshot(int width, int height, Camera screenshotCamera)
{
if (width <= 0 || height <= 0)
{
return null;
}
if (screenshotCamera == null) screenshotCamera = Camera.main;
Texture2D screenshot = new Texture2D(width, height, TextureFormat.RGB24, false);
RenderTexture renderTex = new RenderTexture(width, height, 24);
screenshotCamera.targetTexture = renderTex;
screenshotCamera.Render();
RenderTexture.active = renderTex;
screenshot.ReadPixels(new Rect(0, 0, width, height), 0, 0);
screenshot.Apply(false);
screenshotCamera.targetTexture = null;
RenderTexture.active = null;
Destroy(renderTex);
screenshot = ChangeScreenshot(screenshot);
return screenshot;
}