根據可用的分辨率選高中低清晰度

我這裏是需要可以設定攝像頭普清、高清、超清,攝像頭一般會支持多個分辨率,然後從中選相對應的分比率出來。這裏用一個簡單的算法進行篩選;就是自己設定一組普清、高清、超清對應的分辨率,然後拿對應的分辨率和支持的分辨率作對比,對比的方式是分辨率的長寬相乘後取兩個分辨率的差值,然後取到最接近的那一個

貼代碼

QString selectCameraResolution(int type, QStringList cameraResolutionList)
{
    QSize perfectLow(640,480);
    QSize perfectMiddle(1280,720);
    QSize perfectHigh(1920, 1080);

    int refer = 0;
    switch (type) {
    case 0:
        refer = perfectLow.width()*perfectLow.height();
        break;
    case 1:
        refer = perfectMiddle.width()*perfectMiddle.height();
        break;
    case 2:
        refer = perfectHigh.width()*perfectHigh.height();
        break;
    default:
        break;
    }
    QMap<int,int> map; //<差值,索引>
    int res;
    for(int i = 0;i<cameraResolutionList.size();i++) {
        QString asize = cameraResolutionList.at(i);
        res = asize.section("x",0, 0).toInt()*asize.section("x",1, 1).toInt();
        map.insert(abs(refer-res),i);
    }//map升序
    int index = map.first();
    return cameraResolutionList.at(index);//差值最小的,就是最接近的
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章