本文整理汇总了C++中QPixmap::hasAlpha方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::hasAlpha方法的具体用法?C++ QPixmap::hasAlpha怎么用?C++ QPixmap::hasAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::hasAlpha方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawPattern
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
{
QPixmap* framePixmap = nativeImageForCurrentFrame();
if (!framePixmap) // If it's too early we won't have an image yet.
return;
// Qt interprets 0 width/height as full width/height so just short circuit.
QRectF dr = QRectF(destRect).normalized();
QRect tr = QRectF(tileRect).toRect().normalized();
if (!dr.width() || !dr.height() || !tr.width() || !tr.height())
return;
QPixmap pixmap = *framePixmap;
if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height())
pixmap = pixmap.copy(tr);
CompositeOperator previousOperator = ctxt->compositeOperation();
ctxt->setCompositeOperation(!pixmap.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
QPainter* p = ctxt->platformContext();
QTransform transform(patternTransform);
// If this would draw more than one scaled tile, we scale the pixmap first and then use the result to draw.
if (transform.type() == QTransform::TxScale) {
QRectF tileRectInTargetCoords = (transform * QTransform().translate(phase.x(), phase.y())).mapRect(tr);
bool tileWillBePaintedOnlyOnce = tileRectInTargetCoords.contains(dr);
if (!tileWillBePaintedOnlyOnce) {
QSizeF scaledSize(float(pixmap.width()) * transform.m11(), float(pixmap.height()) * transform.m22());
QPixmap scaledPixmap(scaledSize.toSize());
if (pixmap.hasAlpha())
scaledPixmap.fill(Qt::transparent);
{
QPainter painter(&scaledPixmap);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.setRenderHints(p->renderHints());
painter.drawPixmap(QRect(0, 0, scaledPixmap.width(), scaledPixmap.height()), pixmap);
}
pixmap = scaledPixmap;
transform = QTransform::fromTranslate(transform.dx(), transform.dy());
}
}
/* Translate the coordinates as phase is not in world matrix coordinate space but the tile rect origin is. */
transform *= QTransform().translate(phase.x(), phase.y());
transform.translate(tr.x(), tr.y());
QBrush b(pixmap);
b.setTransform(transform);
p->fillRect(dr, b);
ctxt->setCompositeOperation(previousOperator);
if (imageObserver())
imageObserver()->didDraw(this);
}
示例2: drawPattern
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform,
const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
{
QPixmap* framePixmap = nativeImageForCurrentFrame();
if (!framePixmap) // If it's too early we won't have an image yet.
return;
QPixmap pixmap = *framePixmap;
QRect tr = QRectF(tileRect).toRect();
if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height())
pixmap = pixmap.copy(tr);
QBrush b(pixmap);
b.setTransform(patternTransform);
ctxt->save();
ctxt->setCompositeOperation(op);
QPainter* p = ctxt->platformContext();
if (!pixmap.hasAlpha() && p->compositionMode() == QPainter::CompositionMode_SourceOver)
p->setCompositionMode(QPainter::CompositionMode_Source);
p->setBrushOrigin(phase);
p->fillRect(destRect, b);
ctxt->restore();
if (imageObserver())
imageObserver()->didDraw(this);
}
示例3: draw
// Drawing Routines
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
const FloatRect& src, CompositeOperator op)
{
startAnimation();
QPixmap* image = nativeImageForCurrentFrame();
if (!image)
return;
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, dst, solidColor(), op);
return;
}
IntSize selfSize = size();
ctxt->save();
// Set the compositing operation.
ctxt->setCompositeOperation(op);
QPainter* painter(ctxt->platformContext());
if (!image->hasAlpha() && painter->compositionMode() == QPainter::CompositionMode_SourceOver)
painter->setCompositionMode(QPainter::CompositionMode_Source);
// Test using example site at
// http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
painter->drawPixmap(dst, *image, src);
ctxt->restore();
if (imageObserver())
imageObserver()->didDraw(this);
}
示例4: drawPixmap
void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &srcRect)
{
QPixmapData *data = pixmap.pixmapData();
Q_ASSERT(data->width() && data->height());
Q_ASSERT(data->classId() == QPixmapData::BlitterClass);
QBlittablePixmapData *blitPm = static_cast<QBlittablePixmapData*>(data);
QDirectFbBlitter *dfbBlitter = static_cast<QDirectFbBlitter *>(blitPm->blittable());
dfbBlitter->unlock();
IDirectFBSurface *s = dfbBlitter->m_surface.data();
DFBSurfaceBlittingFlags blittingFlags = DSBLIT_NOFX;
DFBSurfacePorterDuffRule porterDuff = DSPD_SRC;
if (pixmap.hasAlpha()) {
blittingFlags = DSBLIT_BLEND_ALPHACHANNEL;
porterDuff = DSPD_SRC_OVER;
}
m_surface->SetBlittingFlags(m_surface.data(), DFBSurfaceBlittingFlags(blittingFlags));
m_surface->SetPorterDuff(m_surface.data(), porterDuff);
m_surface->SetDstBlendFunction(m_surface.data(), DSBF_INVSRCALPHA);
const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() };
DFBResult result;
if (rect.width() == srcRect.width() && rect.height() == srcRect.height())
result = m_surface->Blit(m_surface.data(), s, &sRect, rect.x(), rect.y());
else {
const DFBRectangle dRect = { rect.x(), rect.y(), rect.width(), rect.height() };
result = m_surface->StretchBlit(m_surface.data(), s, &sRect, &dRect);
}
if (result != DFB_OK)
DirectFBError("QDirectFBBlitter::drawPixmap()", result);
}
示例5: setPixmap
/*!
Sets the pixmap that will be used as the splash screen's image to
\a pixmap.
*/
void QSplashScreen::setPixmap(const QPixmap &pixmap)
{
Q_D(QSplashScreen);
d->pixmap = pixmap;
setAttribute(Qt::WA_TranslucentBackground, pixmap.hasAlpha());
QRect r(QPoint(), d->pixmap.size());
resize(r.size());
move(QApplication::desktop()->screenGeometry().center() - r.center());
if (isVisible())
repaint();
}
示例6: drawTiledPixmap
void QAlphaPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
{
Q_D(QAlphaPaintEngine);
QRectF brect = d->m_transform.mapRect(r);
if (d->m_pass == 0) {
d->m_continueCall = false;
if (pixmap.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pixmap.isQBitmap()) {
d->addAlphaRect(brect);
}
if (d->m_picengine)
d->m_picengine->drawTiledPixmap(r, pixmap, s);
} else {
d->m_continueCall = !d->fullyContained(brect);
}
}
示例7: drawPixmap
void QAlphaPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
{
Q_D(QAlphaPaintEngine);
QRectF tr = d->m_transform.mapRect(r);
if (d->m_pass == 0) {
d->m_continueCall = false;
if (pm.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pm.isQBitmap()) {
d->addAlphaRect(tr);
}
if (d->m_picengine)
d->m_picengine->drawPixmap(r, pm, sr);
} else {
d->m_continueCall = !d->fullyContained(tr);
}
}
示例8: draw
// Drawing Routines
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op)
{
QRectF normalizedDst = dst.normalized();
QRectF normalizedSrc = src.normalized();
startAnimation();
if (normalizedSrc.isEmpty() || normalizedDst.isEmpty())
return;
QPixmap* image = nativeImageForCurrentFrame();
if (!image)
return;
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, normalizedDst, solidColor(), styleColorSpace, op);
return;
}
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
normalizedSrc = adjustSourceRectForDownSampling(normalizedSrc, image->size());
#endif
CompositeOperator previousOperator = ctxt->compositeOperation();
ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
if (ctxt->hasShadow()) {
ShadowBlur* shadow = ctxt->shadowBlur();
GraphicsContext* shadowContext = shadow->beginShadowLayer(ctxt, normalizedDst);
if (shadowContext) {
QPainter* shadowPainter = shadowContext->platformContext();
shadowPainter->drawPixmap(normalizedDst, *image, normalizedSrc);
shadow->endShadowLayer(ctxt);
}
}
ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc);
ctxt->setCompositeOperation(previousOperator);
if (imageObserver())
imageObserver()->didDraw(this);
}
示例9: draw
// Drawing Routines
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op)
{
QRectF normalizedDst = dst.normalized();
QRectF normalizedSrc = src.normalized();
startAnimation();
if (normalizedSrc.isEmpty() || normalizedDst.isEmpty())
return;
QPixmap* image = nativeImageForCurrentFrame();
if (!image)
return;
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, normalizedDst, solidColor(), styleColorSpace, op);
return;
}
CompositeOperator previousOperator = ctxt->compositeOperation();
ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
ContextShadow* shadow = ctxt->contextShadow();
if (shadow->m_type != ContextShadow::NoShadow) {
QPainter* shadowPainter = shadow->beginShadowLayer(ctxt, normalizedDst);
if (shadowPainter) {
shadowPainter->setOpacity(static_cast<qreal>(shadow->m_color.alpha()) / 255);
shadowPainter->drawPixmap(normalizedDst, *image, normalizedSrc);
shadow->endShadowLayer(ctxt);
}
}
ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc);
ctxt->setCompositeOperation(previousOperator);
if (imageObserver())
imageObserver()->didDraw(this);
}
示例10: drawPixmap
void EmfPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &)
{
setClipping();
QMatrix m = painter()->worldMatrix();
QPointF p = m.map(r.topLeft());
int x = qRound(p.x());
int y = qRound(p.y());
int width = qRound(r.width());
int height = qRound(r.height());
#ifdef Q_WS_WIN
HBITMAP hbtmp = NULL;
DWORD op = SRCCOPY;
if (pm.hasAlpha()){
QImage image = pm.scaled(width, height).toImage();
image.invertPixels();
hbtmp = QPixmap::fromImage (image).toWinHBITMAP();
op = SRCINVERT;
} else
hbtmp = pm.scaled(width, height).toWinHBITMAP();
HDC hDC = CreateCompatibleDC(metaDC);
SelectObject(hDC, hbtmp);
BitBlt(metaDC, x, y, width, height, hDC, 0, 0, op);
DeleteObject(hbtmp);
DeleteDC(hDC);
#else
QImage image = pm.scaled(width, height).toImage();
for (int i = 0; i < width; i++){
for (int j = 0; j < height; j++){
QRgb rgb = image.pixel(i, j);
if (qAlpha(rgb) == 255)
SetPixel(metaDC, x + i, y + j, RGB(qRed(rgb), qGreen(rgb), qBlue(rgb)));
}
}
#endif
resetClipping();
}
示例11: setPixmap
/*!
Sets the pixmap that will be used as the splash screen's image to
\a pixmap.
*/
void QSplashScreen::setPixmap(const QPixmap &pixmap)
{
Q_D(QSplashScreen);
if (pixmap.hasAlpha()) {
QPixmap opaque(pixmap.size());
QPainter p(&opaque);
p.fillRect(0, 0, pixmap.width(), pixmap.height(), palette().background());
p.drawPixmap(0, 0, pixmap);
p.end();
d->pixmap = opaque;
} else {
d->pixmap = pixmap;
}
QRect r(0, 0, d->pixmap.size().width(), d->pixmap.size().height());
resize(d->pixmap.size());
move(QApplication::desktop()->screenGeometry().center() - r.center());
if (!isVisible())
d->drawContents();
else
repaint();
}
示例12: loadPixmap
bool PictureContent::loadPixmap(const QPixmap & pixmap, const QString & title)
{
dropNetworkConnection();
delete m_photo;
m_cachedPhoto = QPixmap();
m_opaquePhoto = false;
m_photo = 0;
m_fileUrl = QString();
m_netWidth = 0;
m_netHeight = 0;
m_photo = new CPixmap(pixmap.toImage());
m_opaquePhoto = !pixmap.hasAlpha();
m_fileUrl = QString("data:/");
resetContentsRatio();
setFrameTextEnabled(!title.isEmpty());
setFrameText(title);
applyPostLoadEffects();
// notify image change
emit contentChanged();
return true;
}