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++;
    }

  • 相关阅读:
    设计与声明
    字符串匹配算法——KMP、BM、Sunday
    红黑树——原理
    Linux命令——监视相关
    资源管理
    排序算法——QuickSort、MergeSort、HeapSort(C++实现)
    智能指针——使用与实现
    进程间通信——实现
    构造/析构/赋值运算
    物理内存管理
  • 原文地址:https://www.cnblogs.com/mgstone/p/6004071.html
Copyright © 2011-2022 走看看