eri*_*rik 3 android android-camera
我正在构建一个具有自动对焦的自定义相机,并且只是想知道是否有一种方法来调用本机相机具有的相同自动对焦矩形指示器,或者如果我必须从头构建它...任何示例或教程链接将非常感谢.
Dan*_*ith 11
看看最新的Jelly Bean 4.2相机处理这个问题的方式可能会有所帮助.您可以按如下方式下载相机来源:
git clone https://android.googlesource.com/platform/packages/apps/Camera.git
Run Code Online (Sandbox Code Playgroud)
获得代码后,导航到FocusOverlayManager类和PieRenderer类.如果您之前没有尝试过这个最新版本,则焦距计是一个类似圆形的圆圈,在焦点完成时旋转.你可以在photoshop中制作自己的方块,或者使用我过去使用的这两个中的一个(一个是我制作的iPhone ripoff,另一个是在某些版本的android相机中使用的九个补丁):

果冻豆的例子对于你正在寻找的东西可能有点复杂,所以下面是我为自动对焦实现视觉反馈的方式的一些指导.这个过程可能有些复杂.我不假装我的方式是最好的方法,但这里有一些示例代码,为您提供一般的想法...
在我的相机预览布局xml文件中:
<!-- Autofocus crosshairs -->
<RelativeLayout
android:id="@+id/af_casing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:clipChildren="false" >
<com.package.AutofocusCrosshair
android:id="@+id/af_crosshair"
android:layout_width="65dp"
android:layout_height="65dp"
android:clipChildren="false" >
</com.package.AutofocusCrosshair>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
此AutofocusCrosshair类如下:
public class AutofocusCrosshair extends View {
private Point mLocationPoint;
public AutofocusCrosshair(Context context, AttributeSet attrs) {
super(context, attrs);
}
private void setDrawable(int resid) {
this.setBackgroundResource(resid);
}
public void showStart() {
setDrawable(R.drawable.focus_crosshair_image);
}
public void clear() {
setBackgroundDrawable(null);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的活动中,当我想开始自动对焦时,我会执行以下操作:
mAutofocusCrosshair = (AutofocusCrosshair) findViewById(R.id.af_crosshair);
//Now add your own code to position this within the view however you choose
mAutofocusCrosshair.showStart();
//I'm assuming you'll want to animate this... so start an animation here
findViewById(R.id.af_casing).startAnimation(mAutofocusAnimation);
Run Code Online (Sandbox Code Playgroud)
并确保在动画结束时清除图像:
mAutofocusAnimation.setAnimationListener(new AnimationListener() {
@Override public void onAnimationEnd(Animation arg0) {
mAutofocusCrosshair.clear();
}
@Override public void onAnimationRepeat(Animation arg0) {}
@Override public void onAnimationStart(Animation arg0) {}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7231 次 |
| 最近记录: |