Android 在摄像头[安卓系统]中点击执行指示器以对焦
我有自己的android摄像头应用程序,它可以进行收缩变焦和点击对焦。在点击对焦中,当我触摸屏幕时,我需要画一个矩形或圆形指示器,并在我触摸的任何地方重新绘制。如果自动对焦完成,我还想更改颜色 到目前为止,我已经在屏幕中央画了一个矩形,但如果我触摸屏幕上的某个地方,我就无法重画它 任何实施该计划的想法或建议都将不胜感激 我的密码是Android 在摄像头[安卓系统]中点击执行指示器以对焦,android,android-camera,autofocus,Android,Android Camera,Autofocus,我有自己的android摄像头应用程序,它可以进行收缩变焦和点击对焦。在点击对焦中,当我触摸屏幕时,我需要画一个矩形或圆形指示器,并在我触摸的任何地方重新绘制。如果自动对焦完成,我还想更改颜色 到目前为止,我已经在屏幕中央画了一个矩形,但如果我触摸屏幕上的某个地方,我就无法重画它 任何实施该计划的想法或建议都将不胜感激 我的密码是 @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.rotate(ui_rotation, canvas.getWidth() / 2, canvas.getHeight() / 2);
final float scale = getResources().getDisplayMetrics().density;
int text_y = (int) (20 * scale + 0.5f); // convert dps to pixels
// fine tuning to adjust placement of text with respect to the GUI, depending on orientation
int text_extra_offset_y = 0;
if (ui_rotation == 0) {
text_extra_offset_y = (int) (0.5 * text_y);
} else if (ui_rotation == 180) {
text_extra_offset_y = (int) (2.5 * text_y);
} else if (ui_rotation == 90 || ui_rotation == 270) {
text_extra_offset_y = -(int) (0.5 * text_y);
}
if (previewCamera != null) {
if (this.isOnTimer()) {
long remaining_time = (take_photo_time - System.currentTimeMillis() + 999) / 1000;
if (remaining_time >= 0) {
p.setColor(Color.YELLOW);
p.setTextSize(42 * scale + 0.5f); // convert dps to pixels
p.setTextAlign(Paint.Align.CENTER);
canvas.drawText("" + remaining_time, canvas.getWidth() / 2, canvas.getHeight() / 2, p);
}
}
} else if (previewCamera == null) {
p.setColor(Color.YELLOW);
p.setTextSize(14 * scale + 0.5f); // convert dps to pixels
p.setTextAlign(Paint.Align.CENTER);
int pixels_offset = (int) (20 * scale + 0.5f); // convert dps to pixels
}
if (this.has_zoom && previewCamera != null) {
float zoom_ratio = this.zoom_ratios.get(zoom_factor) / 100.0f;
// only show when actually zoomed in
if (zoom_ratio > 1.0f + 1.0e-5f) {
// Convert the dps to pixels, based on density scale
int pixels_offset_y = 2 * text_y + text_extra_offset_y;
p.setColor(Color.WHITE);
p.setTextSize(14 * scale + 0.5f); // convert dps to pixels
p.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Zoom: " + zoom_ratio + "x", canvas.getWidth() / 2, canvas.getHeight() - pixels_offset_y, p);
}
}
if (previewCamera != null) {
int pixels_offset_y = 1 * text_y + text_extra_offset_y;
p.setColor(Color.WHITE);
p.setTextSize(14 * scale + 0.5f); // convert dps to pixels
p.setTextAlign(Paint.Align.CENTER);
long time_now = System.currentTimeMillis();
}
canvas.restore();
if (this.focus_success == FOCUS_DONE) {
int size = (int) (50 * scale + 0.5f); // convert dps to pixels
if (this.focus_success == FOCUS_SUCCESS)
p.setColor(Color.GREEN);
else if (this.focus_success == FOCUS_FAILED)
p.setColor(Color.RED);
else
p.setColor(Color.GREEN);
p.setStyle(Paint.Style.STROKE);
int pos_x = 0;
int pos_y = 0;
if (has_focus_area) {
pos_x = focus_screen_x;
pos_y = focus_screen_y;
} else {
pos_x = canvas.getWidth() / 2;
pos_y = canvas.getHeight() / 2;
}
canvas.drawRect(pos_x - size, pos_y - size, pos_x + size, pos_y + size, p);
if (focus_complete_time != -1 && System.currentTimeMillis() > focus_complete_time + 1000) {
focus_success = FOCUS_DONE;
}
}
}
在SurfaceCreated()中正确调用onDraw()如果要求类似于“显示类似于录制的按钮”,则在曲面视图中添加按钮“显示”并在需要时隐藏它如果要求类似于“显示类似于录制的按钮”,则,在曲面视图中,根据需要添加一个按钮“显示”和“隐藏”您找到了吗?我有同样的问题!你明白了吗?我有同样的问题!