代码拉取完成,页面将自动刷新
#pragma
#ifndef BINARYFILE_READER_H
#define BINARYFILE_READER_H
#include <iostream>
#include <fstream>
#include <string>
#include <QDebug>
using namespace std;
class BinaryFileReader {
private:
int bytesCount = 0;//读取的字节数
public:
//视频的宽高
int width = 400;
int height = 300;
//文件名
string filename;
//
ifstream in;
public:
bool Init()
{
Close();
in.open(filename, std::ios::binary);
if (!in.is_open())
{
qDebug() << "无法打开文件";
return false;
}
return true;
}
bool Close()
{
if (in) {
in.close();
}
return true;
}
//空间需要外部申请
bool ReadRGB24(char* data)
{
int dataSize = width * height * 3;
in.read(data, dataSize);
if (in.gcount() == 0) {
// 未读取任何字节:可能已到文件结尾或出现错误
if (in.eof()) {
qDebug() << "已到达文件结尾";
return false;
}
else if (in.fail()) {
qDebug() << "读取失败(非EOF原因)";
return false;
}
}
return true;
}
/// <summary>
/// 读取yuv数据
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
bool ReadYUV420P(char* yuv)
{
int dataSize = width * height * 1.5;
in.read(yuv, dataSize);
if (in.gcount() == 0) {
// 未读取任何字节:可能已到文件结尾或出现错误
if (in.eof()) {
qDebug() << "已到达文件结尾";
return false;
}
else if (in.fail()) {
qDebug() << "读取失败(非EOF原因)";
return false;
}
}
return true;
}
bool Read(char* data, int linesize)
{
in.read(data, linesize);
bytesCount = in.gcount();
if (bytesCount == 0) {
// 未读取任何字节:可能已到文件结尾或出现错误
if (in.eof()) {
qDebug() << "已到达文件结尾";
return false;
}
else if (in.fail()) {
qDebug() << "读取失败(非EOF原因)";
return false;
}
}
return true;
}
int getBytesCount()
{
return bytesCount;
}
static BinaryFileReader* Get()
{
static BinaryFileReader reader;
return &reader;
}
static BinaryFileReader* Create()
{
return new BinaryFileReader();
}
protected:
BinaryFileReader() {};
~BinaryFileReader() {}
};
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。