Skip to content

Instantly share code, notes, and snippets.

@davemo
Created April 25, 2012 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davemo/2493916 to your computer and use it in GitHub Desktop.
Save davemo/2493916 to your computer and use it in GitHub Desktop.
Gets input from a Vuforia AR Camera and assigns it to a UnityEngine.Texture2D
using UnityEngine;
using System.Collections;
using System.IO;
using MultiFormatReader = com.google.zxing.MultiFormatReader;
public class TakeScreenshot : MonoBehaviour {
public GUITexture mainProduct;
private MultiFormatReader reader;
void Start() {
reader = new MultiFormatReader();
}
void OnMouseUp() { // for debugging only, the touch input is what counts for mobile
StartCoroutine(ScreenshotEncode());
}
// Update is called once per frame
void Update () {
if(Input.touchCount == 1) {
Touch touch = Input.touches[0];
if(touch.phase == TouchPhase.Ended && guiTexture.HitTest(touch.position)) {
StartCoroutine(ScreenshotEncode());
}
}
}
IEnumerator ScreenshotEncode() {
// wait for graphics to render
yield return new WaitForEndOfFrame();
// create a texture to pass to encoding
Texture2D t = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
// put buffer into texture
t.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
t.Apply();
// i'm assigning it to a GUI Texture here for testing
mainProduct.guiTexture.texture = t;
// what i really want is to pass this texture as input to MultiFormatReader so I can read barcodes.
// reader.decode(t);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment