【QT】二进制读取图像文件并显示
打开对话框选择文件
二进制方式读取文件
转换成图像显示
void MainWindow::showImage()
{
//打开文件对话框 QString lastPath="D:/Englishpath/QTprojects/DATA/videoData";
fileName = QFileDialog::getOpenFileName(this,"OpenFile", lastPath);
if(fileName.isEmpty())
{
QMessageBox::information(this,"Error Message","Select File Failed");
return;
}
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::information(NULL,"失败提示","打开失败",QMessageBox::Ok,QMessageBox::Ok);
return;
}
// QTextStream in(&file);
// ui->textEdit->setText(in.readAll()); //类型转换为可以被ifstream使用的
QString str =fileName;
char *s; QByteArray//QString转换为char*
ba = str.toLatin1();
s = ba.data(); // [1]得到二进制数据;
using std::ifstream;
ifstream i_f_stream(s,ifstream::binary);
i_f_stream.seekg(, i_f_stream.end);
int length = i_f_stream.tellg();
i_f_stream.seekg(, i_f_stream.beg);
char *buffer = new char[length];
i_f_stream.read(buffer, length);//一次性读取
i_f_stream.close(); // [2]缓存数据重构;
QByteArray byteArray(buffer, length); // [3] 构建图片对象并载入二进制数据;
QImage img;
img.loadFromData(byteArray, "png"); // [4] 结果检测(将图片保存到某一目录、用label显示);
img.save(QString("test.bmp"), "png");
ui->d_label->setPixmap(QPixmap::fromImage(img)); delete [] buffer; // QDataStream in(&file);
// while( !in.atEnd())
// {
// QByteArray s;
// in >> s;
// file.close();
// qDebug()<<s<<endl;
// }
}
【转载自】
std::ifstream以二进制方式读取图片文件,用Qt再将其转为图片(QImage::loadFromData()函数使用) - ypy9323的博客 - CSDN博客 https://blog.csdn.net/ypy9323/article/details/81835530
【QT】二进制读取图像文件并显示的更多相关文章
- 【QT】二进制读取图像文件测试
QDataStream in(&file); int n; in >> n ; file.close(); qDebug() << n<<"en& ...
- Qt flash_eraseall nandwrite 进度条显示擦除、烧录
/***************************************************************************** * Qt flash_eraseall n ...
- Python 读取图像文件的性能对比
Python 读取图像文件的性能对比 使用 Python 读取一个保存在本地硬盘上的视频文件,视频文件的编码方式是使用的原始的 RGBA 格式写入的,即无压缩的原始视频文件.最开始直接使用 Pytho ...
- OK335xS tmp75 Qt 温度读取
/******************************************************************* * OK335xS tmp75 Qt 温度读取 * 说明: * ...
- FileReader对象的readAsDataURL方法来读取图像文件
FileReader对象的readAsDataURL方法可以将读取到的文件编码成Data URL.Data URL是一项特殊的技术,可以将资料(例如图片)内嵌在网页之中,不用放到外部文件.使用Dat ...
- 使用FileReader对象的readAsDataURL方法来读取图像文件
使用FileReader对象的readAsDataURL方法来读取图像文件 FileReader对象的readAsDataURL方法可以将读取到的文件编码成Data URL.Data URL是一项 ...
- 使用 Qt 获取 UDP 数据并显示成图片(2)
本文首发于 BriFuture 的 个人博客 在我的前一篇文章 使用 Qt 获取 UDP 数据并显示成图片 中,我讲了如何用 Python 模拟发送数据,如何在 Qt 中高效的接收 UDP 数据包并将 ...
- 转载:使用FileReader对象的readAsDataURL方法来读取图像文件
文章转载自:http://blog.okbase.net/jquery2000/archive/1296.html: FileReader对象的readAsDataURL方法可以将读取到的文件编码成D ...
- 解析 Qt 字库移植并能显示中文 (下篇)
原文http://mobile.51cto.com/symbian-272563.htm 本文介绍的是Qt 字库移植并能显示中文,需要的字体库文件,一般是多个.具体移植那一个,看你使用的字库是什么了, ...
随机推荐
- python中字典的比较
今天碰到一个字典比较的问题,就是比较两个字典的大小,其实这个用的不多,用处也没多少,但是还是记录一下. 字典的比较顺序如下: 1.先比较字典的元素的个数,那个多,就哪个大: 2.比较字典的键,在比较字 ...
- OleVariant Variant
OleVariant ArrayDimCount OleVariant; System.Variants.hpp 判断OleVariant 是否为空 System::OleVariant ov i ...
- cannot nest '/dubboService/src/main/resources' inside '/dubboService/src/main' .To enable the nesting exclude '/resources' from '/dubboService/src/main'
eclipse Maven--->update Project时出现以上错误: cannot nest '/dubboService/src/main/resources' inside '/d ...
- objects & values & types
[objects & values & types] 1.Every object has an identity, a type and a value. An object’s i ...
- 76. Minimum Window Substring (String, Map)
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- ibatis 常用标签
prepend:自动在前面加上:自动新手:自动预:自动前置 property:属性 compareValue:指定的常数,值 //判断不相等: <isNotEqual prepend=" ...
- RNA -seq
RNA -seq RNA-seq目的.用处::可以帮助我们了解,各种比较条件下,所有基因的表达情况的差异. 比如:正常组织和肿瘤组织的之间的差异:检测药物治疗前后,基因表达的差异:检测发育过程中,不同 ...
- 洛谷 P3660 [USACO17FEB]Why Did the Cow Cross the Road III G(树状数组)
题目背景 给定长度为2N的序列,1~N各处现过2次,i第一次出现位置记为ai,第二次记为bi,求满足ai<aj<bi<bj的对数 题目描述 The layout of Farmer ...
- android 的AlertDialog对话框
private int selectedFruitIndex = 0; private void showMsg2() {// Dialog alertDialog = new AlertDial ...
- 阿里云服务器ECS按ctrl+alt+delete无法登录
今天在使用阿里云服务器远程桌面的时候发现怎么也进入不了,远程桌面无法连接,于是想到了在阿里云服务器管理控制台可以使用连接管理终端进行远程桌面连接,下面详细介绍阿里云服务器操作经验. 操作步骤如下 登录 ...