简体   繁体   English

如何在cwac-cam2中打开相机时更改闪光灯设置?

[英]How to change flash setting while camera is open in cwac-cam2?

I ma using cwac-cam2 for creating a camera app. 我使用cwac-cam2来创建相机应用程序。 I am not able to set flash modes while running the camera window and the flash is on always. 我无法在运行相机窗口时设置闪光模式,并且闪光灯始终打开。 I also don't see a button for changing flashmode. 我也没有看到改变flashmode的按钮。 Am i doing something wrong? 难道我做错了什么? Here is the code: 这是代码:

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 will appreciate any help. 我将不胜感激任何帮助。 Thanks. 谢谢。

I am not able to set flash modes while running the camera window 我无法在运行相机窗口时设置闪光模式

Correct. 正确。 Other than the values supplied when you start the activity (eg, CameraActivity ), you have no control over the behavior of that activity while it is in the foreground. 除了启动活动时提供的值(例如, CameraActivity )之外,您无法控制该活动在前台时的行为。 If this is important to you, you will need to use some other library or work with the camera APIs directly. 如果这对您很重要,您将需要使用其他一些库或直接使用相机API。

and the flash is on always 闪光灯一直亮着

That is what your code is asking for, by having ALWAYS as your top-priority flash mode. 这就是您的代码所要求的,通过将ALWAYS作为您的最高优先级闪存模式。

I also don't see a button for changing flashmode 我也没有看到改变flashmode的按钮

I have not implemented that yet. 我还没有实现。 Please keep tabs on this issue . 请密切关注此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM