zoukankan      html  css  js  c++  java
  • (Java和C++)二进制date数据写进android保存为yuv格式

    Java实现函数:

    String strpath = "/storage/emulated/0/DCIM/" +  i + "output.yuv";

     boolean isInfiel= writeFile(strpath, frameData);

    public boolean writeFile(String path, byte[] data) {
                FileOutputStream out = null;
                try {
                    File file = new File(path);
                    File parent = file.getParentFile();
                    if (parent != null && !parent.exists())
                        parent.mkdirs();
                    if (!file.exists()){
                        boolean isok    =  file.createNewFile();
                       out = new FileOutputStream(path);
                       out.write(data);
                       FileDescriptor fd = out.getFD();
                       fd.sync();
                    return true;
                    }
                } catch (Exception e) {
                    e.printStackTrace();

                } finally {
                    try {
                        if (out != null)
                            out.close();
                    } catch (Exception e) {
                    }
                }
                return false;
            }

    C++实现函数:

    static void dumpYuvToFile(const int width, const int height, void *yBuf, void *uvBuf ) {
        static int i = 0;
        char buf[256] = { '' };
        LOGE(" dumpYuvToFile(): i is %d", i);
        snprintf(buf, sizeof(buf), "/data/misc/media/_%d_%d_%d.yuv",  width, height, i);
        FILE* file_fd = fopen(buf, "wb");
        if (file_fd != NULL) {
            void *data = NULL;
            int written_len = 0;
            data = (void *) ((uint8_t *) yBuf);
            written_len += fwrite(data, width * height, 1, file_fd);
            if (NULL == uvBuf)
                data = (void *) ((uint8_t *) yBuf + width * height);
            else
                data = (void *) ((uint8_t *) uvBuf);
            written_len += fwrite(data, width * height / 2, 1, file_fd);
            fclose(file_fd);
            LOGE("%s: dumpYuvToFile(): -------sucess", __func__);
        } else {
            LOGE("%s:dumpYuvToFile(): fail t open file for image dumping", __func__);
        }
        i++;
    }

  • 相关阅读:
    C++后台开发校招面试常见问题
    算术表达式的前缀,中缀,后缀相互转换
    Redis键值对数据库的设计与实现
    C++经典面试题(最全,面中率最高)
    C++开发工程师面试题大合集
    C++中常用的设计模式
    C++中const修饰函数,函数参数,函数返回值的作用
    C++main函数的参数介绍以及如何在main函数前执行一段代码
    Windows系统下安装tensorflow+keras深度学习环境
    第十三周学习总结
  • 原文地址:https://www.cnblogs.com/mgstone/p/6004071.html
Copyright © 2011-2022 走看看