美文网首页
C++ 中一些问题记录

C++ 中一些问题记录

作者: Gavin_2020 | 来源:发表于2020-09-25 11:24 被阅读0次

    一、在编译成.so之后再android中打印c++的信息

    引入头文件:

    
    #include <android/log.h>
    
        #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
    
        #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
    
        #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
    
        #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
    
    
    以上打印方法建议使用error形式,因为部分机型debug以及其他类型的打印优先级较低,有的甚至不会输出打印信息.
    

    在需要打印的地方使用:

    LOGD("height:%d",height);
    
    这里选用%d格式化了打印数据也可以根据需求自己修改。
    
    打印结果例如: heght: 300
    

    二、判断是否为中文

    
    bool CRecognizer::IsChineseChar(WORD DoubleByte)
    
    {
    
      //unicode中文字符范围为4e00-9fa5
    
      BYTE LowByte = LOBYTE(DoubleByte);
    
      BYTE HighByte = HIBYTE(DoubleByte);
    
      if (HighByte == 0x9f) return (LowByte <= 0xa5);
    
      else  return (HighByte >= 0x4e && HighByte < 0x9f);
    
    }
    
    

    三、大小写转换

    
    wchar_t* jstringToCap(JNIEnv*env, jstring jstr)
    
    {
    
    if(jstr==0)
    
    return 0;
    
    int length = env->GetStringLength(jstr);
    
    if (length==0)
    
    {
    
    return 0;
    
    }
    
    const jchar* jcstr = env->GetStringChars(jstr, 0 );
    
    wchar_t* rtn = new wchar_t[length+1];
    
    for(int i=0;i<length;i++){
    
    if (jcstr[i] >= 'a' && jcstr[i] <= 'z')
    
    {
    
    rtn[i]=jcstr[i]+('A'-'a');
    
    }else
    
    rtn[i]=jcstr[i];
    
    }
    
    env->ReleaseStringChars(jstr, jcstr );
    
    rtn[length] = 0;
    
    return rtn;
    
    }
    
    

    四. C++保存时间戳命名图片到android目录下

    // 获取时间戳
    time_t now;
    struct tm *timenow;
    time(&now);
    timenow = localtime(&now);
    long sec = timenow ->tm_sec;
    long min = timenow->tm_min;
    // 格式化androd存储地址(需要strtowst也就是转化为宽字符串形式)
    char buff2[1024] = { 0 };
    sprintf(buff2, "/storage/emulated/0/Android/idcardCrop/dest_img_%d_%d.jpg", min,sec);
    std::wstring wstr = StringFormat::strtowstr(buff2);
    // 写入图片
    tmpimg.imwrite(wstr.c_str(),0);
    

    持续记录更新中。。

    相关文章

      网友评论

          本文标题:C++ 中一些问题记录

          本文链接:https://www.haomeiwen.com/subject/ldxfuktx.html