private static void OnPhoto(Texture2D photo) { Debug.Log($"Photo resolution w: {photo.width}, h: {photo.height}"); float screenAspect = (float)Screen.width / Screen.height; float cameraAspect = (float)photo.width / photo.height; Rect rect; // if screen is wider then camera if (screenAspect > cameraAspect) { float diff = photo.height - photo.width / cameraAspect; rect = new Rect(0, diff / 2, photo.width, photo.height - diff); } else { float diff = photo.width - photo.height * screenAspect; rect = new Rect(diff / 2, 0, photo.width - diff, photo.height); } // crop texture to fit the screen dimension Color[] c = photo.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); photo.Resize((int)rect.width, (int)rect.height, TextureFormat.RGB24, false); photo.SetPixels(c); photo.Apply(); c = null; _cachedPhoto = photo; OnPhotoTaken?.Invoke(photo); }
public void SendOnPhotoTaken(string path) { OnPhotoTaken?.Invoke(this, path); }