第40讲 digital zoom缩放实战 -凯发k8旗舰厅

本讲是android camera专题系列的第40讲,我们介绍android camera2 api专题的digital zoom缩放实战。

更多资源:

资源 描述
在线课程
知识星球 星球名称:深入浅出android camera
星球id: 17296815
wechat 极客笔记圈

判断是否支持digital zoom

float max_zoom = characteristics.get(cameracharacteristics.scaler_available_max_digital_zoom);
camera_features.is_zoom_supported = max_zoom > 0.0f;

平滑的zoom steps计算方式

// set 20 steps per 2x factor
final int steps_per_2x_factor = 20;
//final double scale_factor = math.pow(2.0, 1.0/(double)steps_per_2x_factor);
int n_steps =(int)( (steps_per_2x_factor * math.log(max_zoom   1.0e-11)) / math.log(2.0));
final double scale_factor = math.pow(max_zoom, 1.0/(double)n_steps);
if( mydebug.log ) {
    log.i(tag, "[zoom] n_steps: "   n_steps);
    log.i(tag, "[zoom] scale_factor: "   scale_factor);
}
camera_features.zoom_ratios = new arraylist<>();
camera_features.zoom_ratios.add(100);
double zoom = 1.0;
for(int i=0;i

配置zoom的seekbar

zoomseekbar.setonseekbarchangelistener(null); // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
zoomseekbar.setmax(preview.getmaxzoom());
zoomseekbar.setprogress(preview.getmaxzoom()-preview.getcameracontroller().getzoom());
zoomseekbar.setonseekbarchangelistener(new onseekbarchangelistener() {
    @override
    public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) {
        if( mydebug.log )
            log.d(tag, "zoom onprogresschanged: "   progress);
        // note we zoom even if !fromuser, as various other ui controls (multitouch, volume key zoom, -/  zoomcontrol)
        // indirectly set zoom via this method, from setting the zoom slider
        preview.zoomto(preview.getmaxzoom() - progress);
    }
    @override
    public void onstarttrackingtouch(seekbar seekbar) {
    }
    @override
    public void onstoptrackingtouch(seekbar seekbar) {
    }
});

将zoom值转换为crop region并设置给底层

float zoom = zoom_ratios.get(value)/100.0f;
rect sensor_rect = characteristics.get(cameracharacteristics.sensor_info_active_array_size);
if (mpreviewbuilder.get(capturerequest.distortion_correction_mode) != null) {
    int distortionmode = mpreviewbuilder.get(capturerequest.distortion_correction_mode);
    if (mstaticmetadata.isdistortioncorrectionsupported() &&
            distortionmode == capturerequest.distortion_correction_mode_off) {
        sensor_rect = characteristics.get(cameracharacteristics.sensor_info_pre_correction_active_array_size);
        log.i(tag, "[zoom] distortionmode:"   distortionmode);
    }
}
int left = sensor_rect.width()/2;
int right = left;
int top = sensor_rect.height()/2;
int bottom = top;
int hwidth = (int)(sensor_rect.width() / (2.0*zoom));
int hheight = (int)(sensor_rect.height() / (2.0*zoom));
left -= hwidth;
right  = hwidth;
top -= hheight;
bottom  = hheight;

camera课程

python教程

java教程

web教程

数据库教程

图形图像教程

办公软件教程

linux教程

计算机教程

大数据教程

开发工具教程

android camera2 api

网站地图