{"id":5595,"date":"2019-12-05T14:42:44","date_gmt":"2019-12-05T09:12:44","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=5595"},"modified":"2023-01-20T18:55:26","modified_gmt":"2023-01-20T13:25:26","slug":"custom-camera-using-surfaceview","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/","title":{"rendered":"Custom Camera using SurfaceView"},"content":{"rendered":"<p><strong>SurfaceView<\/strong> is a class provided by <strong>android.view<\/strong> package. It offers a dedicated drawing surface embedded inside of a view hierarchy. We can manage the format of this surface, however, the SurfaceView takes care of putting the surface at the right location on the screen.<\/p>\n<p>In this post, we will use the SurfaceView to preview the camera (android.hardware.camera) onto the screen and capture images using it.<\/p>\n<p>First let us create a new project and add the following dependencies in your app level <strong>build.gradle<\/strong> file which is available at location:\u00a0<strong>app\/build.gradle<\/strong>.<\/p>\n<pre class=\"lang:java decode:true\">dependencies {\r\n    \/*... other dependencies ...*\/\r\n    implementation 'com.google.android.gms:play-services-vision:17.0.2'\r\n}<\/pre>\n<p>In the <strong>AndroidManifest.xml<\/strong> file, add the following permission.<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;uses-permission android:name=\"android.permission.CAMERA\" \/&gt;<\/pre>\n<p>We will also be needing the real-time permission check for android version M and above. Add the below code in your <strong>MainActivity.java\u00a0<\/strong>for handling these checks.<\/p>\n<pre class=\"\">import android.content.DialogInterface;\r\nimport android.content.pm.PackageManager;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.NonNull;\r\nimport android.support.v4.app.ActivityCompat;\r\nimport android.support.v4.content.ContextCompat;\r\nimport android.support.v7.app.AlertDialog;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.widget.Toast;\r\n\r\nimport java.util.ArrayList;\r\n\r\nimport static android.Manifest.permission.CAMERA;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private String[] neededPermissions = new String[]{CAMERA};\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n        boolean result = checkPermission();\r\n        if (result) {\r\n            \/* Code after permission granted *\/\r\n        }\r\n    }\r\n\r\n    private boolean checkPermission() {\r\n        ArrayList&lt;String&gt; permissionsNotGranted = new ArrayList&lt;&gt;();\r\n        for (String permission : neededPermissions) {\r\n            if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {\r\n                permissionsNotGranted.add(permission);\r\n            }\r\n        }\r\n        if (!permissionsNotGranted.isEmpty()) {\r\n            boolean shouldShowAlert = false;\r\n            for (String permission : permissionsNotGranted) {\r\n                shouldShowAlert = ActivityCompat.shouldShowRequestPermissionRationale(this, permission);\r\n            }\r\n            if (shouldShowAlert) {\r\n                showPermissionAlert(permissionsNotGranted.toArray(new String[0]));\r\n            } else {\r\n                requestPermissions(permissionsNotGranted.toArray(new String[0]));\r\n            }\r\n            return false;\r\n        }\r\n        return true;\r\n    }\r\n\r\n    private void showPermissionAlert(final String[] permissions) {\r\n        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);\r\n        alertBuilder.setCancelable(true);\r\n        alertBuilder.setTitle(\"Permission Required\");\r\n        alertBuilder.setMessage(\"Camea permission is required to move forward.\");\r\n        alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {\r\n            public void onClick(DialogInterface dialog, int which) {\r\n                requestPermissions(permissions);\r\n            }\r\n        });\r\n        AlertDialog alert = alertBuilder.create();\r\n        alert.show();\r\n    }\r\n\r\n    private void requestPermissions(String[] permissions) {\r\n        ActivityCompat.requestPermissions(MainActivity.this, permissions, 1001);\r\n    }\r\n\r\n    @Override\r\n    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {\r\n        if (requestCode == 1001) {\r\n            for (int result : grantResults) {\r\n                if (result == PackageManager.PERMISSION_DENIED) {\r\n                    Toast.makeText(MainActivity.this, \"This permission is required\", Toast.LENGTH_LONG).show();\r\n                    checkPermission();\r\n                    return;\r\n                }\r\n            }\r\n            \/* Code after permission granted *\/\r\n        }\r\n        super.onRequestPermissionsResult(requestCode, permissions, grantResults);\r\n    }\r\n}<\/pre>\n<p>Now let&#8217;s build our layout file. So open <strong>activity_main.xml<\/strong> file and add the below code.<\/p>\n<pre class=\"lang:default decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;FrameLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n\r\n    &lt;SurfaceView\r\n        android:id=\"@+id\/surfaceView\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:visibility=\"gone\" \/&gt;\r\n\r\n    &lt;TextView\r\n        android:id=\"@+id\/tv_capture\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_gravity=\"center_horizontal|bottom\"\r\n        android:background=\"#8cffffff\"\r\n        android:padding=\"20dp\"\r\n        android:text=\"Click\"\r\n        android:textStyle=\"bold\"\r\n        android:visibility=\"gone\" \/&gt;\r\n\r\n    &lt;ImageView\r\n        android:id=\"@+id\/iv_picture\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:visibility=\"gone\" \/&gt;\r\n&lt;\/FrameLayout&gt;<\/pre>\n<p>Now in MainActivity.java, let us set up our implementation for <strong>SurfaceView<\/strong>.<\/p>\n<p>To initialize <strong>SurfaceView<\/strong>, use the following code :<\/p>\n<pre class=\"lang:default decode:true\">private SurfaceView surfaceView;\r\nsurfaceView = findViewById(R.id.surfaceView);<\/pre>\n<p>Now to setup <strong>SurfaceHolder<\/strong>, we need to first create a <strong>FaceDetector<\/strong> object.<\/p>\n<pre class=\"lang:default decode:true\">private FaceDetector detector;\r\ndetector = new FaceDetector.Builder(this)\r\n        .setProminentFaceOnly(true) \/\/ optimize for single, relatively large face\r\n        .setTrackingEnabled(true) \/\/ enable face tracking\r\n        .setClassificationType(\/* eyes open and smile *\/ FaceDetector.ALL_CLASSIFICATIONS)\r\n        .setMode(FaceDetector.FAST_MODE) \/\/ for one face this is OK\r\n        .build();\r\n\/\/ Check if detector has been initialized properly\r\nif (!detector.isOperational()) {\r\n    Log.w(\"MainActivity\", \"Detector Dependencies are not yet available\");\r\n} else {\r\n    Log.w(\"MainActivity\", \"Detector Dependencies are available\");\r\n    \/* Check camera permission here *\/\r\n}<\/pre>\n<p>Now setup <strong>SurfaceHolder<\/strong> and add a callback to it.<\/p>\n<pre class=\"lang:java decode:true\">private CameraSource cameraSource;\r\nprivate void setupSurfaceHolder() {\r\n    cameraSource = new CameraSource.Builder(this, detector)\r\n            .setFacing(CameraSource.CAMERA_FACING_FRONT)\r\n            .setRequestedFps(2.0f)\r\n            .setAutoFocusEnabled(true)\r\n            .build();\r\n\r\n    surfaceHolder = surfaceView.getHolder();\r\n    surfaceHolder.addCallback(new SurfaceHolder.Callback() {\r\n        @Override\r\n        public void surfaceCreated(SurfaceHolder holder) {\r\n            try {\r\n                cameraSource.start(surfaceHolder);\r\n                detector.setProcessor(new LargestFaceFocusingProcessor(detector,\r\n                    new Tracker&lt;Face&gt;()));\r\n            } catch (IOException e) {\r\n                e.printStackTrace();\r\n            }\r\n        }\r\n\r\n        @Override\r\n        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {\r\n\r\n        }\r\n\r\n        @Override\r\n        public void surfaceDestroyed(SurfaceHolder holder) {\r\n            cameraSource.stop();\r\n        }\r\n    });\r\n}<\/pre>\n<p>Now to click the picture, we need to setup <strong>OnClickListener<\/strong> to click the picture and display it.<\/p>\n<pre class=\"\">findViewById(R.id.tv_capture).setOnClickListener(new View.OnClickListener() {\r\n    @Override\r\n    public void onClick(View v) {\r\n        clickImage();\r\n    }\r\n});\r\nprivate void clickImage() {\r\n    if (cameraSource != null) {\r\n        cameraSource.takePicture(\/*shutterCallback*\/null, new CameraSource.PictureCallback() {\r\n            @Override\r\n            public void onPictureTaken(byte[] bytes) {\r\n                Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);\r\n                ((ImageView) findViewById(R.id.iv_picture)).setImageBitmap(bitmap);\r\n                setViewVisibility(R.id.iv_picture);\r\n                findViewById(R.id.surfaceView).setVisibility(View.GONE);\r\n                findViewById(R.id.tv_capture).setVisibility(View.GONE);\r\n            }\r\n        });\r\n    }\r\n}<\/pre>\n<p>Below is the complete code for <strong>MainActivity.java<\/strong>.<\/p>\n<pre class=\"\">import android.content.DialogInterface;\r\nimport android.content.pm.PackageManager;\r\nimport android.graphics.Bitmap;\r\nimport android.graphics.BitmapFactory;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.NonNull;\r\nimport android.support.v4.app.ActivityCompat;\r\nimport android.support.v4.content.ContextCompat;\r\nimport android.support.v7.app.AlertDialog;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.util.Log;\r\nimport android.view.SurfaceHolder;\r\nimport android.view.SurfaceView;\r\nimport android.view.View;\r\nimport android.widget.ImageView;\r\nimport android.widget.Toast;\r\n\r\nimport com.google.android.gms.vision.CameraSource;\r\nimport com.google.android.gms.vision.Tracker;\r\nimport com.google.android.gms.vision.face.Face;\r\nimport com.google.android.gms.vision.face.FaceDetector;\r\nimport com.google.android.gms.vision.face.LargestFaceFocusingProcessor;\r\n\r\nimport java.io.IOException;\r\nimport java.util.ArrayList;\r\n\r\nimport static android.Manifest.permission.CAMERA;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private String[] neededPermissions = new String[]{CAMERA};\r\n    private SurfaceView surfaceView;\r\n    private CameraSource cameraSource;\r\n    private SurfaceHolder surfaceHolder;\r\n    private FaceDetector detector;\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n        surfaceView = findViewById(R.id.surfaceView);\r\n\r\n        detector = new FaceDetector.Builder(this)\r\n                .setProminentFaceOnly(true) \/\/ optimize for single, relatively large face\r\n                .setTrackingEnabled(true) \/\/ enable face tracking\r\n                .setClassificationType(\/* eyes open and smile *\/ FaceDetector.ALL_CLASSIFICATIONS)\r\n                .setMode(FaceDetector.FAST_MODE) \/\/ for one face this is OK\r\n                .build();\r\n\r\n        if (!detector.isOperational()) {\r\n            Log.w(\"MainActivity\", \"Detector Dependencies are not yet available\");\r\n        } else {\r\n            Log.w(\"MainActivity\", \"Detector Dependencies are available\");\r\n            if (surfaceView != null) {\r\n                boolean result = checkPermission();\r\n                if (result) {\r\n                    setViewVisibility(R.id.tv_capture);\r\n                    setViewVisibility(R.id.surfaceView);\r\n                    setupSurfaceHolder();\r\n                }\r\n            }\r\n        }\r\n\r\n        findViewById(R.id.tv_capture).setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n                clickImage();\r\n            }\r\n        });\r\n    }\r\n\r\n    private boolean checkPermission() {\r\n        ArrayList&lt;String&gt; permissionsNotGranted = new ArrayList&lt;&gt;();\r\n        for (String permission : neededPermissions) {\r\n            if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {\r\n                permissionsNotGranted.add(permission);\r\n            }\r\n        }\r\n        if (!permissionsNotGranted.isEmpty()) {\r\n            boolean shouldShowAlert = false;\r\n            for (String permission : permissionsNotGranted) {\r\n                shouldShowAlert = ActivityCompat.shouldShowRequestPermissionRationale(this, permission);\r\n            }\r\n            if (shouldShowAlert) {\r\n                showPermissionAlert(permissionsNotGranted.toArray(new String[0]));\r\n            } else {\r\n                requestPermissions(permissionsNotGranted.toArray(new String[0]));\r\n            }\r\n            return false;\r\n        }\r\n        return true;\r\n    }\r\n\r\n    private void showPermissionAlert(final String[] permissions) {\r\n        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);\r\n        alertBuilder.setCancelable(true);\r\n        alertBuilder.setTitle(\"Permission Required\");\r\n        alertBuilder.setMessage(\"Camea permission is required to move forward.\");\r\n        alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {\r\n            public void onClick(DialogInterface dialog, int which) {\r\n                requestPermissions(permissions);\r\n            }\r\n        });\r\n        AlertDialog alert = alertBuilder.create();\r\n        alert.show();\r\n    }\r\n\r\n    private void requestPermissions(String[] permissions) {\r\n        ActivityCompat.requestPermissions(MainActivity.this, permissions, 1001);\r\n    }\r\n\r\n    @Override\r\n    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {\r\n        if (requestCode == 1001) {\r\n            for (int result : grantResults) {\r\n                if (result == PackageManager.PERMISSION_DENIED) {\r\n                    Toast.makeText(MainActivity.this, \"This permission is required\", Toast.LENGTH_LONG).show();\r\n                    checkPermission();\r\n                    return;\r\n                }\r\n            }\r\n            setViewVisibility(R.id.tv_capture);\r\n            setViewVisibility(R.id.surfaceView);\r\n            setupSurfaceHolder();\r\n        }\r\n        super.onRequestPermissionsResult(requestCode, permissions, grantResults);\r\n    }\r\n\r\n    private void setViewVisibility(int id) {\r\n        View view = findViewById(id);\r\n        if (view != null) {\r\n            view.setVisibility(View.VISIBLE);\r\n        }\r\n    }\r\n\r\n    private void setupSurfaceHolder() {\r\n        cameraSource = new CameraSource.Builder(this, detector)\r\n                .setFacing(CameraSource.CAMERA_FACING_FRONT)\r\n                .setRequestedFps(2.0f)\r\n                .setAutoFocusEnabled(true)\r\n                .build();\r\n\r\n        surfaceHolder = surfaceView.getHolder();\r\n        surfaceHolder.addCallback(new SurfaceHolder.Callback() {\r\n            @Override\r\n            public void surfaceCreated(SurfaceHolder holder) {\r\n                try {\r\n                    cameraSource.start(surfaceHolder);\r\n                    detector.setProcessor(new LargestFaceFocusingProcessor(detector,\r\n                            new Tracker&lt;Face&gt;()));\r\n                } catch (IOException e) {\r\n                    e.printStackTrace();\r\n                }\r\n            }\r\n\r\n            @Override\r\n            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {\r\n\r\n            }\r\n\r\n            @Override\r\n            public void surfaceDestroyed(SurfaceHolder holder) {\r\n                cameraSource.stop();\r\n            }\r\n        });\r\n    }\r\n\r\n    private void clickImage() {\r\n        if (cameraSource != null) {\r\n            cameraSource.takePicture(\/*shutterCallback*\/null, new CameraSource.PictureCallback() {\r\n                @Override\r\n                public void onPictureTaken(byte[] bytes) {\r\n                    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);\r\n                    ((ImageView) findViewById(R.id.iv_picture)).setImageBitmap(bitmap);\r\n                    setViewVisibility(R.id.iv_picture);\r\n                    findViewById(R.id.surfaceView).setVisibility(View.GONE);\r\n                    findViewById(R.id.tv_capture).setVisibility(View.GONE);\r\n                }\r\n            });\r\n        }\r\n    }\r\n}<\/pre>\n<p>That&#8217;s all for this post. Stay tuned for the next post to learn how to click the picture on the blinking of your eyes.<\/p>\n<p>InnovationM is a globally renowned\u00a0<a href=\"https:\/\/www.innovationm.com\/android-app-development\">Android app development company in\u00a0India<\/a> that caters to a strong &amp; secure Android app development, iOS app development, hybrid app development services. Our commitment &amp; engagement towards our target gives us brighter in the world of technology and has led us to establish success stories consecutively which makes us the best\u00a0<a href=\"https:\/\/www.innovationm.com\/ios-app-development\">iOS app development company in India<\/a>.<\/p>\n<p>Thanks for giving your valuable time. Keep reading and keep learning \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SurfaceView is a class provided by android.view package. It offers a dedicated drawing surface embedded inside of a view hierarchy. We can manage the format of this surface, however, the SurfaceView takes care of putting the surface at the right location on the screen. In this post, we will use the SurfaceView to preview the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5686,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,71],"tags":[159,420,417,416,414,413,418,419,415],"class_list":["post-5595","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","category-mobile","tag-android","tag-android-camera-surfaceview-example","tag-android-surfaceview","tag-cloud-vision-api","tag-custom-camera-using-surfaceview","tag-google-vision","tag-image-recognition","tag-surface-view-in-android","tag-surfaceview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Custom Camera using SurfaceView - InnovationM - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom Camera using SurfaceView - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"SurfaceView is a class provided by android.view package. It offers a dedicated drawing surface embedded inside of a view hierarchy. We can manage the format of this surface, however, the SurfaceView takes care of putting the surface at the right location on the screen. In this post, we will use the SurfaceView to preview the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-05T09:12:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-20T13:25:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2019\/11\/Custom-Camera-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1144\" \/>\n\t<meta property=\"og:image:height\" content=\"635\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Custom Camera using SurfaceView\",\"datePublished\":\"2019-12-05T09:12:44+00:00\",\"dateModified\":\"2023-01-20T13:25:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/\"},\"wordCount\":317,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Custom-Camera-1.png\",\"keywords\":[\"Android\",\"android camera surfaceview example\",\"android surfaceview\",\"cloud vision api\",\"custom camera using surfaceview\",\"Google Vision\",\"image recognition\",\"surface view in android\",\"surfaceview\"],\"articleSection\":[\"Android\",\"Mobile\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/\",\"name\":\"Custom Camera using SurfaceView - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Custom-Camera-1.png\",\"datePublished\":\"2019-12-05T09:12:44+00:00\",\"dateModified\":\"2023-01-20T13:25:26+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Custom-Camera-1.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Custom-Camera-1.png\",\"width\":1144,\"height\":635,\"caption\":\"Custom Camera using SurfaceView\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-camera-using-surfaceview\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom Camera using SurfaceView\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom Camera using SurfaceView - InnovationM - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/","og_locale":"en_US","og_type":"article","og_title":"Custom Camera using SurfaceView - InnovationM - Blog","og_description":"SurfaceView is a class provided by android.view package. It offers a dedicated drawing surface embedded inside of a view hierarchy. We can manage the format of this surface, however, the SurfaceView takes care of putting the surface at the right location on the screen. In this post, we will use the SurfaceView to preview the [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/","og_site_name":"InnovationM - Blog","article_published_time":"2019-12-05T09:12:44+00:00","article_modified_time":"2023-01-20T13:25:26+00:00","og_image":[{"width":1144,"height":635,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2019\/11\/Custom-Camera-1.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Custom Camera using SurfaceView","datePublished":"2019-12-05T09:12:44+00:00","dateModified":"2023-01-20T13:25:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/"},"wordCount":317,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2019\/11\/Custom-Camera-1.png","keywords":["Android","android camera surfaceview example","android surfaceview","cloud vision api","custom camera using surfaceview","Google Vision","image recognition","surface view in android","surfaceview"],"articleSection":["Android","Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/","url":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/","name":"Custom Camera using SurfaceView - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2019\/11\/Custom-Camera-1.png","datePublished":"2019-12-05T09:12:44+00:00","dateModified":"2023-01-20T13:25:26+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2019\/11\/Custom-Camera-1.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2019\/11\/Custom-Camera-1.png","width":1144,"height":635,"caption":"Custom Camera using SurfaceView"},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/custom-camera-using-surfaceview\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom Camera using SurfaceView"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/5595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=5595"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/5595\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/5686"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=5595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=5595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=5595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}