我想在我的自定义相机中实现tap to focus功能.这是Google提供的基本代码https://github.com/googlesamples/android-Camera2Basic
这里是我认为我应该添加我的功能的代码片段如果有人已经实现了Camera2 API,请帮忙!
private void lockFocus() {
try {
// This is how to tell the camera to lock focus.
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_START);
// Tell #mCaptureCallback to wait for the lock.
mState = STATE_WAITING_LOCK;
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 我有来自https://github.com/googlesamples/android-Camera2Basic的Camera2的代码.
我面临的问题是,当我转向我的前置摄像头时,我无法捕捉图片,但使用后置摄像头可以正常工作.
有没有人实施Camera2 Api请帮忙!
这是代码片段:
private void setUpCameraOutputs(int width, int height) {
Activity activity = getActivity();
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
// We don't use a front facing camera in this sample.
int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
Log.i(TAG,"Front Cam ID: "+ facing);
if (characteristics.get(CameraCharacteristics.LENS_FACING)==CameraCharacteristics.LENS_FACING_FRONT)
{
StreamConfigurationMap map = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
// For still image captures, we use the largest available size.
Size largest = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
new …Run Code Online (Sandbox Code Playgroud) 我是android开发的新手.这是我遇到的问题.我正在使用Android Studio.我查了很多网站,他们说要导入相关的课程.完成后,问题仍然存在.任何帮助表示赞赏.
任何人都可以帮我这个,我一直在寻找解决方案.
这是代码:
package com.example.veeresh.myapplication;
//import statements
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(
//error: cannot find symbol class onClickListener
new Button.onClickListener()
{
public void onClick(View v)
{
TextView text1 = (TextView)findViewById(R.id.text1);
text1.setText("Veeresh Here");
}
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
错误:(
24,27 )错误:无法找到符号类onClickListener 错误:任务':app:compileDebugJava'的执行失败.
编译失败; 请参阅编译器错误输出以获取详细信
基本上我正在尝试使用(MinSDK设置为11)添加后退功能
getActionBar().setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)
这是我的功能:
public class DetailActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_layout);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
Logcat详细信息:
07-28 18:26:50.030 19793-19795/? E/art? Failed writing handshake bytes (-1 of 14): Broken pipe
Run Code Online (Sandbox Code Playgroud)