如何在 cwac-cam2 中打开相机时更改闪光灯设置?
How to change flash setting while camera is open in cwac-cam2?
我可能会使用 cwac-cam2 创建相机应用程序。当 运行 相机 window 并且闪光灯始终开启时,我无法设置闪光灯模式。我也没有看到用于更改闪光灯模式的按钮。难道我做错了什么?这是代码:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private static final FlashMode[] FLASH_MODES={
FlashMode.ALWAYS,
FlashMode.AUTO,
FlashMode.OFF
};
private static final int REQUEST_PORTRAIT_RFC=1337;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!Environment.MEDIA_MOUNTED
.equals(Environment.getExternalStorageState())) {
Toast
.makeText(this, "Cannot access external storage!",
Toast.LENGTH_LONG)
.show();
finish();
}
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
capturePortraitFFC();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void capturePortraitFFC() {
Intent i;
i=new CameraActivity.IntentBuilder(this)
.skipConfirm()
.facing(Facing.BACK)
.facingExactMatch()
.to(new File(getExternalFilesDir(null), (new SimpleDateFormat("yyyyMMdd'-'HHmmss").format(new Date())).replaceAll(" ", "_") + ".jpg"))
.updateMediaStore()
.flashModes(FLASH_MODES)
.zoomStyle(ZoomStyle.SEEKBAR)
.debugSavePreviewFrame()
.debug()
.build();
startActivityForResult(i, REQUEST_PORTRAIT_RFC);
}
}
如有任何帮助,我将不胜感激。谢谢
I am not able to set flash modes while running the camera window
正确。除了启动 activity 时提供的值(例如 CameraActivity
),您无法控制 activity 在前台时的行为。如果这对您很重要,您将需要使用其他库或直接使用相机 API。
and the flash is on always
这就是您的代码所要求的,将 ALWAYS
作为您的最高优先级闪光模式。
I also don't see a button for changing flashmode
我还没有实现。请密切关注 this issue。
我可能会使用 cwac-cam2 创建相机应用程序。当 运行 相机 window 并且闪光灯始终开启时,我无法设置闪光灯模式。我也没有看到用于更改闪光灯模式的按钮。难道我做错了什么?这是代码:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private static final FlashMode[] FLASH_MODES={
FlashMode.ALWAYS,
FlashMode.AUTO,
FlashMode.OFF
};
private static final int REQUEST_PORTRAIT_RFC=1337;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!Environment.MEDIA_MOUNTED
.equals(Environment.getExternalStorageState())) {
Toast
.makeText(this, "Cannot access external storage!",
Toast.LENGTH_LONG)
.show();
finish();
}
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
capturePortraitFFC();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void capturePortraitFFC() {
Intent i;
i=new CameraActivity.IntentBuilder(this)
.skipConfirm()
.facing(Facing.BACK)
.facingExactMatch()
.to(new File(getExternalFilesDir(null), (new SimpleDateFormat("yyyyMMdd'-'HHmmss").format(new Date())).replaceAll(" ", "_") + ".jpg"))
.updateMediaStore()
.flashModes(FLASH_MODES)
.zoomStyle(ZoomStyle.SEEKBAR)
.debugSavePreviewFrame()
.debug()
.build();
startActivityForResult(i, REQUEST_PORTRAIT_RFC);
}
}
如有任何帮助,我将不胜感激。谢谢
I am not able to set flash modes while running the camera window
正确。除了启动 activity 时提供的值(例如 CameraActivity
),您无法控制 activity 在前台时的行为。如果这对您很重要,您将需要使用其他库或直接使用相机 API。
and the flash is on always
这就是您的代码所要求的,将 ALWAYS
作为您的最高优先级闪光模式。
I also don't see a button for changing flashmode
我还没有实现。请密切关注 this issue。