在内存上将Iplimage压缩为jpeg [英] Compressing Iplimage to jpeg on memory

查看:160
本文介绍了在内存上将Iplimage压缩为jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我将实时在网络上传输网络摄像头图像.但是Iplimage的大小很大,因此不适合udp数据包.我必须将其压缩为jpeg格式.我进行了一些研究,其中有许多示例确实将图片保存在磁盘上,然后读取到内存中.但是我想在内存中做到这一点.我在我的项目上使用Qt.

I am working on a project that I will transfer webcam images on the network , real time. But Iplimage has a big size so it does not fit in a udp packet. I have to compress it to jpeg format. I made some research many examples do save the picture on disk then read to the memory. But I want do it on memory. I am using Qt on my project.

是否有用于压缩内存上的Iplimage的解决方案? Qt可能对此有解决方案吗?

Is there any solution for compressing Iplimage on memory ? May be Qt has a solution for that ?

推荐答案

Qt具有 QImageWriter 类,它支持JPEG格式并允许指定压缩级别.您可以使用它将QImage数据保存到 QByteArray .下面是一个示例:

Qt has QImageWriter class which supports JPEG format and allows specifying compression level. You can use it to save QImage data to QByteArray. Below is an example:

QImage image("/home/image_from.png");

QByteArray array;
QBuffer buffer(&array);

// write image to memory buffer
QImageWriter writer;
writer.setDevice(&buffer);
writer.setFormat("JPEG");
writer.setCompression(9);
writer.write(image);

,或者您可以使用 QPixmap 保存方法;它还允许将内存缓冲区指定为输出设备:

or you can use QPixmap save method; it also allows specifying memory buffer as output device:

QImage image("/home/image_from.png");
QPixmap pixmap = QPixmap::fromImage(image);

QByteArray array;
QBuffer buffer(&array);
pixmap.save(&buffer, "JPEG", 9);

希望这会有所帮助

这篇关于在内存上将Iplimage压缩为jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆