当前位置: 首页 > news >正文

QImage函数setAlphaChannel

        最近使用QImage的函数setAlphaChannel时遇到了一个坑,花了不少时间才弄清楚:在使用这个函数后,图像格式都会变成QImage::Format_ARGB32_Premultiplied。

先看下setAlphaChannel在帮助文档的说明:

void QImage::setAlphaChannel(const QImage &alphaChannel)
Sets the alpha channel of this image to the given alphaChannel.
If alphaChannel is an 8 bit alpha image, the alpha values are 
used directly. Otherwise, alphaChannel is converted to 
8 bit grayscale and the intensity of the pixel values is used.
If the image already has an alpha channel, 
the existing alpha channel is multiplied with the new one. 
If the image doesn't have an alpha channel 
it will be converted to a format that does.
The operation is similar to painting alphaChannel as 
an alpha image over this image using QPainter::CompositionMode_DestinationIn.

大概意思:

setAlphaChannel函数为图像指定透明通道,如果alphaChannel是单通道的8位图片,那么直接使用,如果不是就转换成8位的灰度图片在作为透明通道。

如果图像已经有透明通道,那么两个通道会相乘,如果图像没有透明通道则会将图像转换成有透明通道的格式。

帮助文档只说了如果图像没有透明通道,那么会将图像转化成有透明通道的图像,但在使用过程中会发现,只要使用了setAlphaChannel,图像都会将格式转化成

QImage::Format_ARGB32_Premultiplied格式。

测试如下:

void MainWindow::on_pushButton_clicked()
{QImage src1(100,100,QImage::Format_RGB32);QImage src2(100,100,QImage::Format_RGB16);QImage src3(100,100,QImage::Format_ARGB32);QImage alpha(100,100,QImage::Format_Grayscale8);alpha.fill(Qt::white);src1.setAlphaChannel(alpha);src2.setAlphaChannel(alpha);src3.setAlphaChannel(alpha);qDebug()<<(src1.format() == QImage::Format_ARGB32_Premultiplied);qDebug()<<(src2.format() == QImage::Format_ARGB32_Premultiplied);qDebug()<<(src3.format() == QImage::Format_ARGB32_Premultiplied);
}

打印出的结果都是true,也就是图像格式都转换成了QImage::Format_ARGB32_Premultiplied。

http://www.lryc.cn/news/187009.html

相关文章:

  • 区块链、隐私计算、联邦学习、人工智能的关联
  • Unity可视化Shader工具ASE介绍——4、ASE的自定义模板使用
  • FastAPI学习-22.response 异常处理 HTTPException
  • 75.颜色分类
  • 浅谈分散式存储项目MEMO
  • ansible角色运行指定角色路径
  • 【数据结构-字符串 三】【字符串转换】字符串解码
  • LabVIEW中不同颜色连线的含义
  • 如何才能在Ubuntu系统部署RabbitMQ服务器并公网访问
  • PCL点云处理之使用变换矩阵对点云去中心化(二百零七)
  • ubuntu编译安装并测试opencv
  • Vue3最佳实践 第七章 TypeScript 上
  • 【maven私库nexus开机自启动】
  • ctfshow-web5(md5弱比较)
  • 【GIT版本控制】--子模块
  • 享元模式 基于享元模式的对象池设计与开发应用(设计模式与开发实践 P12)
  • postman测试文件上传接口教程
  • 【bug日记】spring项目使用配置类和测试类操作数据库
  • Django之主键外键详解
  • HDLbits: ece241 2014 q7b
  • C++多态的理解
  • 关于深拷贝和浅拷贝你需要了解的内容
  • Visual Studio自定义模板参数、备注
  • 机器学习-数值特征
  • Rocky(centos)安装nginx并设置开机自启
  • Android约束布局ConstraintLayout的Guideline,CardView
  • LVGL8.3.6 Flex(弹性布局)
  • 计算机算法分析与设计(8)---图像压缩动态规划算法(含C++)代码
  • React 状态管理 - Mobx 入门(上)
  • OLED透明屏技术在智能手机、汽车和广告领域的市场前景