码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • QImage函数setAlphaChannel


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

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

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

    大概意思:

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

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

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

    QImage::Format_ARGB32_Premultiplied格式。

    测试如下:

    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QImage src1(100,100,QImage::Format_RGB32);
    4. QImage src2(100,100,QImage::Format_RGB16);
    5. QImage src3(100,100,QImage::Format_ARGB32);
    6. QImage alpha(100,100,QImage::Format_Grayscale8);
    7. alpha.fill(Qt::white);
    8. src1.setAlphaChannel(alpha);
    9. src2.setAlphaChannel(alpha);
    10. src3.setAlphaChannel(alpha);
    11. qDebug()<<(src1.format() == QImage::Format_ARGB32_Premultiplied);
    12. qDebug()<<(src2.format() == QImage::Format_ARGB32_Premultiplied);
    13. qDebug()<<(src3.format() == QImage::Format_ARGB32_Premultiplied);
    14. }

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

  • 相关阅读:
    微信小程序三级分销商城源码系统+区域代理+完整的部署教程
    广州穗雅医院健康小贴士:秋冬季节唇炎防护指南
    lv7 嵌入式开发-网络编程开发 13 UNIX域套接字
    接雨水问题
    docker 使用2台服务器安装 Canal 同步 Mysql 数据
    Java:如何在PowerPoint幻灯片中创建散点图
    基于智能优化算法的交通流模拟器(Matlab代码实现)
    产品设计的起点:从企业的角度寻找切入点
    react-grapesjs——开源代码学习与修改(初出茅庐)
    阿里云和AWS对比研究三——存储产品对比
  • 原文地址:https://blog.csdn.net/hulinhulin/article/details/133720487
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号