QT QImage像素操作 [英] QT QImage pixel manipulation

查看:3055
本文介绍了QT QImage像素操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建QT GUI应用程序并使用QImage打开图像。
我的问题是我无法弄清楚如何使用QImage的bit()和scanline()
方法来获得每像素级别的访问权限。

I am building a QT GUI application and use QImage for opening images. My problem is that I can't figure out how to use QImage's bit() and scanline() methods to get access at per pixel level.

我看过这篇文章 Qt QImage像素操作问题
但这仅适用于每行的第一个像素。这是正确的还是我错了?

I've seen this post Qt QImage pixel manipulation problems but this is only for the first pixel of each row. Is this correct or I got it all wrong?

提前谢谢

推荐答案

scanlines 对应的高度在图像中,列对应于图像的宽度。

The scanlines correspond to the the height of image, the columns correspond to the width of the image.

根据文档,原型看起来像 uchar * QImage :: scanline( int i),或类似的 const 版本。

According to the docs, the prototype looks like uchar* QImage::scanline(int i), or a similar const version.

但是,作为评论者指出,因为数据依赖于机器架构和图像,所以 NOT 应直接使用 uchar * 。相反,请使用以下内容:

But, as a commenter pointed out, because the data is dependent on the machine architecture and image, you should NOT use the uchar * directly. Instead, use something like the following:

QRgb *rowData = (QRgb*)img.scanLine(row);
QRgb pixelData = rowData[col];
int red = qRed(pixelData);

这篇关于QT QImage像素操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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