gpt4 book ai didi

Android - 使用搜索栏更改 LED 亮度

转载 作者:行者123 更新时间:2023-11-29 00:34:50 29 4
gpt4 key购买 nike

我制作了一个手电筒应用程序,可以通过按钮打开相机的 LED 灯。如果可能的话,我希望能够使用搜索栏更改 LED 灯的亮度。

如果这有帮助的话,这是我按钮中的代码:

public class FlashLightActivity extends Activity {


private boolean isLighOn = false;
private Camera camera;
private Button button;

@Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();

if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}

camera = Camera.open();
final Parameters p = camera.getParameters();

button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {

if (isLighOn) {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
}
}
});
}
}

最佳答案

检查 Increase/Decrease Brightness of Image 给出的示例

然后在搜索栏进度更改上执行如下所示

 int brightness;
SeekBar seekbarbrightness=(SeekBar)findViewById(R.id.seekBar1);
seekbarbrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub

}

@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub

}

@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {

// TODO Auto-generated method stub

brightness=progress;
Bitmap bitmap=doBrightness(originalbitmap,brightness);
imageView.setImageBitmap(bitmap);
}
});

关于Android - 使用搜索栏更改 LED 亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13206412/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com