写入图像
Writing to an image
本文关键字:图像 更新时间:2023-10-16
我正在尝试从HTTP流中提取图像。我要求使用 C++ 而不是其他库,除了libpcap
来捕获数据包。这是我正在做的事情:
if ((tcp->th_flags & TH_ACK) != 0) {
i = tcp->th_ack;
const char *payload = (const char *) (packet + SIZE_ETHERNET + size_ip + size_tcp);
size_payload = ntohs(ip->ip_len) - (size_ip + size_tcp);
std::string temp(payload);
dict.insert(std::pair<u_int,std::string>(tcp->th_ack,temp));
}
然后我连接所有具有相同 ACK 编号的数据包:
std::string ss;
for(itt=dict.begin(); itt!= dict.end(); ++itt) {
std::string temp((*itt).second);
ss.append(temp);
}
std::ofstream file;
file.open("image.jpg", std::ios::out | std::ios::binary)
file << ss;
file.close();
现在,当我将ss
写入文件时,文件的大小远小于传输的图像。这是编写二进制文件的正确方法吗?
我正在尝试在C++中执行此操作
使用 std::string
会在第一个以 null 结尾的字符处切断数据(即使 std::string 不是以 null 结尾的字符串)。std::string 的构造函数采用 char* 并假定一个以 null 结尾的字符串。这是一个证明:
char sample [] = {'a', 'b', ' ', 'c', 'd', ' ', 'e'};
std::string ss(sample);
您应该使用 std::vector 来存储数据。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 将RGB图像保存为PPM格式
- 将图像添加到资源文件夹UWP C++
- 彩色图像的卤化物处理平均值
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- 重新定位图像时如何前进到下一个内存块
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- 为什么 BMP 图像上的 imwrite 会卡住/不返回?
- Gstreamer:每 5 秒使用多文件墨水保存图像/jpeg
- 如何使用CImg打开图像?
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- 使用 CUDA 和纹理进行图像减法