- Home /
Question by
gratoo · Mar 03, 2015 at 12:11 PM ·
androidcameraresolutionwebcamtexturecrop
WebCamTexture resolution and cropping problem on Android
I'm using the WebCamTexture class to take pictures with the front-facing camera of my Android tablet and I'm having a couple of issues:
The native camera app of my Android tablet takes photos up to 2688x1520 but Unity only allows me to take 1920x1080.
Then the 1920x1080 that Unity returns me doesn't look like the 1920x1080 that the native camera app takes. The Unity one is cropped and scaled back to match the 1920x1080 resolution.
Has anybody experienced that problem? Is there a way to overcome this problem without having to write a plugin to access Android native methods?
Here's what I'm doing:
private void InitializeCamera () {
WebCamDevice[] devices = WebCamTexture.devices;
deviceName = devices[0].name;
webCamTexture = new WebCamTexture(deviceName, 1920, 1080, 12);
renderer.material.mainTexture = webCamTexture;
webCamTexture.Play();
}
public void TakePhoto()
{
Texture2D photo = new Texture2D(webCamTexture.width, webCamTexture.height);
photo.SetPixels(webCamTexture.GetPixels());
photo.Apply();
//Encode to a JPG
byte[] bytes = photo.EncodeToJPG();
//Write out the JPG
string photoName = "photo" + photoCount.ToString() + ".jpg";
File.WriteAllBytes("/sdcard/unityPhotos/" + photoName, bytes);
photoCount++;
}
Comment