check if camera has 4k

vanKraster 181 Reputation points
2023-01-02T10:01:46.903+00:00

Hi to all,

I would like to know if there is a way to determine if the device has 4k camera capabilities.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,661 Reputation points Microsoft Vendor
    2023-01-03T07:11:24.397+00:00

    Hello,

    You can use native API to judge the device has 4k camera capabilities.
    For Android, you need to add camera permission.

       <uses-permission android:name="android.permission.CAMERA" />  
    

    Then use this var res=cameraParams.SupportedPictureSizes; get all of camera capabilities. If the value of width is over 4096 and the value of height is over 2160, this device has 4k camera capabilities.

       public bool getBackCameraResolutionInMp()  
               {  
                   int noOfCameras = Android.Hardware.Camera.NumberOfCameras;  
                   float maxResolution = -1;  
                   long pixelCount = -1;  
                   for (int i = 0; i < noOfCameras; i++)  
                   {  
                       Android.Hardware.Camera.CameraInfo cameraInfo = new CameraInfo();  
                         
                       Android.Hardware.Camera.GetCameraInfo(i, cameraInfo);  
                      if (cameraInfo.Facing == Android.Hardware.CameraFacing.Back)  
                       {  
                           Android.Hardware.Camera camera = Android.Hardware.Camera.Open(i); ;  
                           Android.Hardware.Camera.Parameters cameraParams = camera.GetParameters();  
                          var res=cameraParams.SupportedPictureSizes;  
                           for (int j = 0; j < cameraParams.SupportedPictureSizes.Count; j++)  
                           {  
                               if (cameraParams.SupportedPictureSizes[j].Width>4096&& cameraParams.SupportedPictureSizes[j].Height>2160)  
                               {  
                                   return true;  
                               }  
                               return false;  
                               
                           }  
                          camera.Release();  
                       }  
                   }  
         
                  return false;  
               }  
    

    For iOS, you can use supportedMaxPhotoDimensions to get the maximum photo dimension

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful