I’m trying to make a project capture & stream gameplay screen with transparent background.(use blackmagic decklink card)
I haven’t worked with capture card before. Is there any example code or suggest for programing with capture card?
I’ve found a source code which take a screenshot with transparent background here :
http://stackoverflow.com/questions/25080597/how-do-i-capture-a-screenshot-in-unity3d-with-a-transparent-background
I test it in my code and it got good shot with transparent background :
using UnityEngine;
using System.Collections;
public class GetScreenShot : MonoBehaviour {
public int resWidth = 1920;
public int resHeight = 1080;
public Texture2D frameShot(){
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
camera.targetTexture = null;
RenderTexture.active = null;
Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
Texture2D frameshot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false);
frameshot.LoadImage(bytes);
return frameshot;
}
public GUITexture picture;
void LateUpdate() {
if(Input.GetKeyDown (KeyCode.C)){
picture.texture = frameShot();
}
}
}
However, when I take shot continuously , RAM full. I realize each shot RAM used increase 30MB and never decrease as long as project still playing.(follow task manager windows)
Is there any way to resolve it? Will it work better if I using capture card for this work ?(in fact , I don’t know how to use capture card to do this)
Thanks