I. Addition of Shutter Sound
camera.shutterCallback method is called. This method is used in camera.takePicture method. It can be seen from the parameter setting of camera.takePicture(Camera.ShutterCallback shutter, Camera.PictureCallback raw, Camera.PictureCallback jpeg). The first parameter is the callback after capturing the image. At this time, sound can be set to indicate that the user's image has been captured. . The second parameter is to call back the original image data, which can be null. The third parameter is the method of image callback processing.private Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() { public void onShutter() { tone = new ToneGenerator(AudioManager.STREAM_MUSIC, ToneGenerator.MIN_VOLUME); } };
2. Realization of Flash Opening Control
Two Buttens are set up here to control the turn-on and turn-off of the flash. This method is very simple. Because I have just started contacting, I do not know how to set up a Butten, and then through selector control, tried many times, all failed, I hope God gives a direction.public void flashSelection() { flash_on = (ImageButton) findViewById(R.id.falsh_on); flash_on.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != camera) { Camera.Parameters parameters = camera.getParameters(); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); camera.setParameters(parameters); } } }); flash_off = (ImageButton) findViewById(R.id.falsh_off); flash_off.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Camera.Parameters parameters = camera.getParameters(); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); camera.setParameters(parameters); } }); }
3. Realization of Different Butten s Corresponding to Different Trigger Events
public void onClick(final View v) { Thread thread = new Thread(new Runnable() { @Override public void run() { switch (v.getId()) { case R.id.take: camera.takePicture(shutterCallback,null,new MyPictureCallback()); System.out.println(">++++++++<"); break; case R.id.take1: camera.takePicture(shutterCallback,null,new SecondPictureCallback()); System.out.println(">?????????<"); Message message = new Message(); message.what = res; handler.sendMessage(message); break; default: break; } } }); thread.start(); }
private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 0: tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//Set Underlines tv.setText(Html.fromHtml(" " + res + "")); break; default: break; } } };
Here a thread is called to run some time-consuming operations. When dealing with two or more Buttens, it should be noted that two or more Buttens'IDs are used to judge, and View in onClick function is used to judge different id s, so as to realize different triggers.