Custom camera Overview (general steps, precautions, difficulties encountered, pixel references)

Source: Internet
Author: User

General steps:

1. Check and access camera: Create Code to check the existence of camera and requested access;

2. Create a preview class: Inherit surfaceview to create a camera preview class and implement the surfaceholder interface. This class is used to preview real-time images from camera.

3. Build a preview layout: Once the camera preview class is available, you can combine this preview class with the user interface control you want to create a view layout.

4. Create a listener for collection: connect the listener with the interface control that responds to user actions (such as pressing the button) to start image or video collection.

5. Collect and save files: write code for the images or videos you actually collect and save the output.

6. Release camera: After using camera, your application must release camera so that other applications can use it.

 

Note:

Camera hardware is a shared resource that must be carefully managed. Therefore, when your application uses it, it cannot conflict with other applications. (We will discuss how to check the camera hardware, how to request access to camera, how to collect images and videos, and how to release camera after the application is used .)

Warning when your application uses camera, remember to call the camera. Release () method to release the camera object. If your application does not correctly release camera, all subsequent views will fail to access camera, including your own applications, and may close your application or other applications.

 

Difficulties:

1. A black screen is displayed during activity switching.

By default, the Android app starts with a black screen. Similarly, when you use the startactivity (intent) method to enter a new activity from an activity, a black screen will appear for a short time. The reason is that the first activity loads some data, such as initializing the list data and sending a request to the server to obtain the data. The existence of this problem is determined by the Android Application Framework, but it does affect the user experience. Next we will solve this black screen problem!

Step 1: Customize theme to make the target activity transparent

Add the theme of the custom activity to your_project/RES/values/styles. XML, as shown below:

<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <! -- Activity topic --> <style name = "activitytheme" parent = "@ Android: style/theme"> <item name = "Android: using wistranslucent "> true </item> </style> </resources>


<Item name = "Android: javaswistranslucent"> true </item> indicates that the target activity (the activity to be started) is transparent. It is easy to understand that two activities, A and B; Start B in A, because B is transparent and the background is still a, which solves this short black screen problem.

Step 2: Modify manifest and apply theme to the target activity.

After theme is defined, it is time to bind theme to the corresponding activity. This code is mainly implemented in manifest and the following attributes are added to the activity:

<activity android:name=".activity.PlacingOrderStep1Activity" android:theme="@style/activityTheme" /> 

Solve this problem!

 

 

Pixel reference:

8 million 3264x1836 8 m

5 million 2592x1944 5 m (implemented currently)

3 million 2048x1536 3.2 m

Uxga 1600x1200 1920x1088 2 m

XGA 1024x768 0.8 m svga 800x600

VGA 640x480 0.3 m

Custom camera Overview (general steps, precautions, difficulties encountered, pixel references)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.