0
我是新來的android,目前正在使用相機API的應用程序。我在應用程序中執行縮放功能時遇到問題。我正在使用相機套件API來製作應用程序,並且相機套件Api不提供對縮放控件的支持。請幫我提供所需的代碼。自一週以來我無法弄清楚。我需要對相機預覽執行縮放。Add zoom to camera android
這是我的代碼。
public class MicroscopeAcitvity extends AppCompatActivity implements View.OnClickListener {
CameraView cameraView;
ImageButton cameraTakePic;
ImageButton buttonFlash;
Camera mCamera; //= Camera.open();
Camera.Parameters params;
TextView T1,T2;
int counter = 0;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_microscope_acitvity);
cameraView = (CameraView) findViewById(R.id.camera);
cameraTakePic = (ImageButton) findViewById(R.id.button_take_picture);
cameraTakePic.setOnClickListener(this);
buttonFlash = (ImageButton) findViewById(R.id.button_Flash);
buttonFlash.setOnClickListener(this);
T1 = (TextView) findViewById(R.id.flash_text1);
T1.setOnClickListener(this);
//T1.setVisibility(View.GONE);
T2 = (TextView) findViewById(R.id.flash_text2);
T2.setOnClickListener(this);
//T2.setVisibility(View.GONE);
cameraView.setCameraListener(new CameraListener() {
@Override
public void onPictureTaken(byte[] picture) {
super.onPictureTaken(picture);
// Create a bitmap
Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
}
});
cameraView.setFocus(CameraKit.Constants.FOCUS_TAP);
}
@Override
protected void onResume() {
super.onResume();
cameraView.start();
}
@Override
protected void onPause() {
cameraView.stop();
super.onPause();
}
@Override
public void onClick(View v) {
int id;
id = v.getId();
if(id == R.id.button_take_picture){
cameraView.captureImage();
}
if(id == R.id.button_Flash){
if(counter % 2 != 0){
T1.setVisibility(View.VISIBLE);
T2.setVisibility(View.VISIBLE);
counter = counter+1;
}
else{
T1.setVisibility(View.GONE);
T2.setVisibility(View.GONE);
counter = counter+1;
}
}
if(id == R.id.flash_text1){
T1.setTextColor(Color.RED);
T2.setTextColor(Color.DKGRAY);
cameraView.setFlash(CameraKit.Constants.FLASH_ON);
}
if (id == R.id.flash_text2){
T2.setTextColor(Color.RED);
T1.setTextColor(Color.DKGRAY);
cameraView.setFlash(CameraKit.Constants.FLASH_OFF);
}
}
}