Hi all,
Im using Vuforia AR
I intent to take a screenshot for a number (Barcode - OCR code) from a specific place in the screen, i create a Plane gameobject for use like a marker.
This is my code for the momment for find the Plane in screen and then take a screenshot:
private void TakeScreenShot()
{
Vector3 screenPos = Camera.main.WorldToScreenPoint(ocrCropGrid.GetComponent<Transform>().position);
Bounds ocrBounds = ocrCropGrid.GetComponent<Renderer>().bounds;
Vector3 posStart = Camera.main.WorldToScreenPoint(new Vector3(ocrBounds.min.x, ocrBounds.min.y, ocrBounds.min.z));
Vector3 posEnd = Camera.main.WorldToScreenPoint(new Vector3(ocrBounds.max.x, ocrBounds.max.y, ocrBounds.min.z));
Debug.Log("posStart:" + posStart);
Debug.Log("posEnd:" + posEnd);
int widthX = (int)(posEnd.x - posStart.x);
int widthY = (int)(posEnd.y - posStart.y);
Debug.Log("widthX:" + widthX);
Debug.Log("widthY:" + widthY);
screenShotOCRCode.ReadPixels(new Rect(screenPos.x - (widthX / 2), screenPos.y - (widthY / 2), widthX, widthY), 0, 0);
screenShotOCRCode.Apply();
//SAVE SCREENSHOT
byte[] image = screenShotOCRCode.EncodeToJPG();
File.WriteAllBytes(Application.dataPath + "/../Screenshots/CardOCR.jpg", image);
Debug.Log("Screenshot Saved");
}
The problem is the position, the X (screenPos.x) position not match camera the Y (screenPos.y) is fine with a common. And with vuforia camera the screenshots go wrong
Any help is appreciated.
Sorry for my english.