开发者社区> 问答> 正文

QImage ALPHA:报错

我是这样加载的一张图片 QImage mag(“a.png”);

然后更改了mag的ALPHA通道 ,我手动更改的 就是把每个像素的第四位赋值了

但是QPainter好像没管ALPHA通道 求解释

展开
收起
kun坤 2020-06-06 13:59:00 555 0
1 条回答
写回答
取消 提交回答
  • 问题解决了 convertToFormat转换下格式

    但是又有新问题了 转换前和转换后每一个像素里面的数据都一摸一样 为啥就显示不一样呢

    ######

    bool QImageReader::read(QImage *image)
    {
        if (!image) {
            qWarning("QImageReader::read: cannot read into null pointer");
            return false;
        }

        if (!d->handler && !d->initHandler())
            return false;

        // set the handler specific options.
        if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) {
            if ((d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull())
                || d->clipRect.isNull()) {
                // Only enable the ScaledSize option if there is no clip rect, or
                // if the handler also supports ClipRect.
                d->handler->setOption(QImageIOHandler::ScaledSize, d->scaledSize);
            }
        }
        if (d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull())
            d->handler->setOption(QImageIOHandler::ClipRect, d->clipRect);
        if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull())
            d->handler->setOption(QImageIOHandler::ScaledClipRect, d->scaledClipRect);
        if (d->handler->supportsOption(QImageIOHandler::Quality))
            d->handler->setOption(QImageIOHandler::Quality, d->quality);

        // read the image
        if (!d->handler->read(image)) {
            d->imageReaderError = InvalidDataError;
            d->errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unable to read image data"));
            return false;
        }

        // provide default implementations for any unsupported image
        // options
        if (d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull()) {
            if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) {
                if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
                    // all features are supported by the handler; nothing to do.
                } else {
                    // the image is already scaled, so apply scaled clipping.
                    if (!d->scaledClipRect.isNull())
                        *image = image->copy(d->scaledClipRect);
                }
            } else {
                if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
                    // supports scaled clipping but not scaling, most
                    // likely a broken handler.
                } else {
                    if (d->scaledSize.isValid()) {
                        *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                    }
                    if (d->scaledClipRect.isValid()) {
                        *image = image->copy(d->scaledClipRect);
                    }
                }
            }
        } else {
            if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) {
                // in this case, there's nothing we can do. if the
                // plugin supports scaled size but not ClipRect, then
                // we have to ignore ClipRect."

                if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
                    // nothing to do (ClipRect is ignored!)
                } else {
                    // provide all workarounds.
                    if (d->scaledClipRect.isValid()) {
                        *image = image->copy(d->scaledClipRect);
                    }
                }
            } else {
                if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
                    // this makes no sense; a handler that supports
                    // ScaledClipRect but not ScaledSize is broken, and we
                    // can't work around it.
                } else {
                    // provide all workarounds.
                    if (d->clipRect.isValid())
                        *image = image->copy(d->clipRect);
                    if (d->scaledSize.isValid())
                        *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                    if (d->scaledClipRect.isValid())
                        *image = image->copy(d->scaledClipRect);
                }
            }
        }

        return true;
    }

    ######

    找到核心代码了就是看不懂 到底怎么回事

    2020-06-06 13:59:05
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载