void ScreenSelector::grabColor() { m_selectionRect = m_selectionRect.normalized(); QDesktopWidget* desktop = QApplication::desktop(); int screenNum = desktop->screenNumber(m_selectionRect.topLeft()); QScreen* screen = QGuiApplication::screens()[screenNum]; QPixmap screenGrab = screen->grabWindow(desktop->winId(), m_selectionRect.x(), m_selectionRect.y(), m_selectionRect.width(), m_selectionRect.height()); QImage image = screenGrab.toImage(); int numPixel = image.width() * image.height(); int sumR = 0; int sumG = 0; int sumB = 0; for (int x = 0; x < image.width(); ++x) { for (int y = 0; y < image.height(); ++y) { QColor color = image.pixel(x, y); sumR += color.red(); sumG += color.green(); sumB += color.blue(); } } QColor avgColor(sumR / numPixel, sumG / numPixel, sumB / numPixel); emit colorPicked(avgColor); }
void IdentityWidget::updateData(const RsPeerDetails &pgp_details) { //if (_details != pgp_details) { _details = pgp_details; _havePGPDetail = true; _nickname = QString::fromUtf8(_details.name.c_str()); if (!_haveGXSId) m_myName = _nickname; ui->labelName->setText(m_myName); if (_haveGXSId) { ui->labelName->setToolTip(tr("GXS name:").append(" "+m_myName).append("\n") .append(tr("PGP name:").append(" "+_nickname))); } else {//if (m_myName != _nickname) ui->labelName->setToolTip(tr("PGP name:").append(" "+_nickname)); }//else (m_myName != _nickname) QFont font = ui->labelName->font(); font.setItalic(true); ui->labelName->setFont(font); _keyId = QString::fromStdString(_details.gpg_id.toStdString()); ui->labelKeyId->setText(_keyId); ui->labelKeyId->setToolTip(tr("PGP id:").append(" "+_keyId)); QPixmap avatar; AvatarDefs::getAvatarFromGpgId(_details.gpg_id.toStdString(), avatar); if (_avatar != avatar.toImage()) { _avatar = avatar.toImage(); _scene->clear(); _scene->addPixmap(avatar.scaled(ui->graphicsView->width(),ui->graphicsView->height())); emit imageUpdated(); }//if (_avatar != avatar.toImage()) //}//if (_details != gpg_details) }
QPixmap TabBar::makePixmapForDrag(int index) { std::vector< std::pair<QString,QIcon > > tabs; for (int i = 0; i < count(); ++i) { tabs.push_back(std::make_pair(tabText(i),tabIcon(i))); } //remove all tabs while (count() > 0) { removeTab(0); } ///insert just the tab we want to screen shot addTab(tabs[index].second, tabs[index].first); QPixmap currentTabPixmap = Gui::screenShot(_tabWidget->tabAt(index)); #if QT_VERSION < 0x050000 QPixmap tabBarPixmap = QPixmap::grabWidget(this); #else QPixmap tabBarPixmap = grab(); #endif ///re-insert all the tabs into the tab bar removeTab(0); for (U32 i = 0; i < tabs.size(); ++i) { addTab(tabs[i].second, tabs[i].first); } QImage tabBarImg = tabBarPixmap.toImage(); QImage currentTabImg = currentTabPixmap.toImage(); //now we just put together the 2 pixmaps and set it with mid transparancy QImage ret(currentTabImg.width(),currentTabImg.height() + tabBarImg.height(),QImage::Format_ARGB32_Premultiplied); for (int y = 0; y < tabBarImg.height(); ++y) { QRgb* src_pixels = reinterpret_cast<QRgb*>(tabBarImg.scanLine(y)); for (int x = 0; x < ret.width(); ++x) { if (x < tabBarImg.width()) { QRgb pix = src_pixels[x]; ret.setPixel(x, y, qRgba(qRed(pix), qGreen(pix), qBlue(pix), 255)); } else { ret.setPixel(x, y, qRgba(0, 0, 0, 128)); } } } for (int y = 0; y < currentTabImg.height(); ++y) { QRgb* src_pixels = reinterpret_cast<QRgb*>(currentTabImg.scanLine(y)); for (int x = 0; x < ret.width(); ++x) { QRgb pix = src_pixels[x]; ret.setPixel(x, y + tabBarImg.height(), qRgba(qRed(pix), qGreen(pix), qBlue(pix), 255)); } } return QPixmap::fromImage(ret); }
void QGeoMapPixmapObject::setPixmap(const QPixmap &pixmap) { QPixmap curPixmap = d_ptr->pixmap; if (curPixmap.isNull() && pixmap.isNull()) return; if ((curPixmap.isNull() && !pixmap.isNull()) || (!curPixmap.isNull() && pixmap.isNull()) || (curPixmap.toImage() != pixmap.toImage())) { d_ptr->pixmap = pixmap; emit pixmapChanged(pixmap); } }
QImage ImageBufferDataPrivateUnaccelerated::toQImage() const { QPaintEngine* paintEngine = m_pixmap.paintEngine(); if (!paintEngine || paintEngine->type() != QPaintEngine::Raster) return m_pixmap.toImage(); // QRasterPixmapData::toImage() will deep-copy the backing QImage if there's an active QPainter on it. // For performance reasons, we don't want that here, so we temporarily redirect the paint engine. QPaintDevice* currentPaintDevice = paintEngine->paintDevice(); paintEngine->setPaintDevice(0); QImage image = m_pixmap.toImage(); paintEngine->setPaintDevice(currentPaintDevice); return image; }
void WebPage::slotIconChanged(void) { QIcon icon = m_browser->GetIcon(); if (icon.isNull()) { //FIXME use a default icon here? m_listItem->setImage(NULL); } else { if (m_listItem) { QPixmap pixmap = icon.pixmap(32, 32); QImage image = pixmap.toImage(); image = image.scaled( QSize(32,32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); MythImage *mimage = GetMythPainter()->GetFormatImage(); mimage->Assign(image); m_listItem->setImage(mimage); } } m_parent->m_pageList->Refresh(); }
void EC_ChatBubble::Refresh() { if (renderer_.expired() ||!billboardSet_ || !billboard_) return; // If no messages in the log, hide the chat bubble. if (messages_.size() == 0) { billboardSet_->setVisible(false); return; } else billboardSet_->setVisible(true); // Get pixmap with chat bubble and text rendered to it. QPixmap pixmap = GetChatBubblePixmap(); if (pixmap.isNull()) return; // Create texture QImage img = pixmap.toImage(); Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream((void*)img.bits(), img.byteCount())); std::string tex_name("ChatBubbleTexture" + renderer_.lock()->GetUniqueObjectName()); Ogre::TextureManager &manager = Ogre::TextureManager::getSingleton(); Ogre::Texture *tex = dynamic_cast<Ogre::Texture *>(manager.create(tex_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).get()); assert(tex); tex->loadRawData(stream, img.width(), img.height(), Ogre::PF_A8R8G8B8); // Set new material with the new texture name in it. std::string newMatName = std::string("material") + renderer_.lock()->GetUniqueObjectName(); Ogre::MaterialPtr material = OgreRenderer::CloneMaterial("UnlitTexturedSoftAlpha", newMatName); OgreRenderer::SetTextureUnitOnMaterial(material, tex_name); billboardSet_->setMaterialName(newMatName); }
QPixmap StyleHelper::alphaBlend(const QPixmap& src) { QImage imageSrc = src.toImage(); QImage imageCopy = imageSrc.convertToFormat(QImage::Format_ARGB32); QRect rectSrc = imageCopy.rect(); int w = rectSrc.width(); int h = rectSrc.height(); uchar* pixels = imageCopy.bits(); uint mask = 0; QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied; // Make a QImage out of the QPixmap and add alpha QImage image(w, h, imageFormat); if (!image.isNull()) { int bytes_per_line = w * sizeof(QRgb); for (int y = 0; y < h; ++y) { QRgb* dest = (QRgb*) image.scanLine(y); const QRgb* src = (const QRgb *) (pixels + y * bytes_per_line); for (int x = 0; x < w; ++x) { const uint pixel = src[x]; if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0) dest[x] = pixel | 0xff000000; else dest[x] = pixel | mask; } } } return QPixmap::fromImage(image, Qt::AutoColor); }
nsresult nsIconChannel::Init(nsIURI* aURI) { nsCOMPtr<nsIMozIconURI> iconURI = do_QueryInterface(aURI); NS_ASSERTION(iconURI, "URI is not an nsIMozIconURI"); nsAutoCString stockIcon; iconURI->GetStockIcon(stockIcon); nsAutoCString iconSizeString; iconURI->GetIconSize(iconSizeString); uint32_t desiredImageSize; iconURI->GetImageSize(&desiredImageSize); nsAutoCString iconStateString; iconURI->GetIconState(iconStateString); bool disabled = iconStateString.EqualsLiteral("disabled"); // This is a workaround for // https://bugzilla.mozilla.org/show_bug.cgi?id=662299 // Try to find corresponding freedesktop icon and fallback to empty QIcon // if failed. QIcon icon = QIcon::fromTheme(QString(stockIcon.get()).replace("gtk-", "edit-")); QPixmap pixmap = icon.pixmap(desiredImageSize, desiredImageSize, disabled ? QIcon::Disabled : QIcon::Normal); QImage image = pixmap.toImage(); return moz_qicon_to_channel(&image, iconURI, getter_AddRefs(mRealChannel)); }
void KoRecentDocumentsPane::updatePreview(const KFileItem& fileItem, const QPixmap& preview) { if (preview.isNull()) { return; } QStandardItem* rootItem = model()->invisibleRootItem(); for (int i = 0; i < rootItem->rowCount(); ++i) { KoFileListItem* item = static_cast<KoFileListItem*>(rootItem->child(i)); if (item->fileItem().url() == fileItem.url()) { item->setData(preview, Qt::UserRole); QImage icon = preview.toImage(); icon = icon.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation); icon = icon.convertToFormat(QImage::Format_ARGB32); icon = icon.copy((icon.width() - 64) / 2, (icon.height() - 64) / 2, 64, 64); item->setData(QPixmap::fromImage(icon), Qt::DecorationRole); if (m_documentList->selectionModel()->currentIndex() == item->index()) { m_previewLabel->setPixmap(preview); } break; } } }
void EWASiteDrawer::drawShadowedPixmap(QPainter *p, const QPixmap &pix, int dx, int dy, bool onlyshdw ) { QImage msk = pix.toImage(); QImage shadow(msk.width()+2*fsize, msk.height()+2*fsize, QImage::Format_ARGB32); double divisor=0.0; for(int i=0;i<2*fsize+1;i++) for(int j=0;j<2*fsize+1;j++) divisor+=filter[i][j]; for(int y=0;y<shadow.height(); y++) for(int x=0;x<shadow.width(); x++){ int l=0; for(int sy=-fsize;sy<=fsize;sy++) for(int sx=-fsize;sx<=fsize;sx++){ int tx = x+sx-fsize; int ty = y+sy-fsize; if(tx<0 || ty<0 || tx>=msk.width() || ty>=msk.height()) l+=(int)(filter[sx+fsize][sy+fsize]*255); else l+=(int)(filter[sx+fsize][sy+fsize]*(255-qAlpha(msk.pixel(tx, ty)))); } l=(int)(l/divisor); l = 255 - l; l=qBound(0, l, 225); shadow.setPixel(x, y,qRgba(0, 0, 0, l)); } p->drawImage(dx, dy, shadow); if(!onlyshdw) p->drawPixmap(dx, dy, pix); }
QImage BitmapHelper::drawGrid(const QImage *source, int scale) { QImage result = QImage(*source); if (scale > 5) { QPixmap pixmap = QPixmap::fromImage(result); QPainter painter(&pixmap); painter.setPen(QColor("silver")); for (int x = 0; x < pixmap.width(); x += scale) { painter.drawLine(x, 0, x, pixmap.height()); } painter.drawLine(pixmap.width() - 1, 0, pixmap.width() - 1, pixmap.height()); for (int y = 0; y < pixmap.height(); y += scale) { painter.drawLine(0, y, pixmap.width(), y); } painter.drawLine(0, pixmap.height() - 1, pixmap.width(), pixmap.height() - 1); result = pixmap.toImage(); } return result; }
void AudioEngine::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { if ( requestData.caller != s_aeInfoIdentifier || requestData.type != Tomahawk::InfoSystem::InfoAlbumCoverArt ) { return; } QVariantMap playInfo; playInfo["message"] = QString( "Tomahawk is playing \"%1\" by %2 on album %3." ) .arg( m_currentTrack->track() ) .arg( m_currentTrack->artist()->name() ) .arg( m_currentTrack->album()->name() ); if ( !output.isNull() && output.isValid() ) { QVariantMap returnedData = output.value< QVariantMap >(); const QByteArray ba = returnedData["imgbytes"].toByteArray(); if ( ba.length() ) { QPixmap pm; pm.loadFromData( ba ); playInfo["image"] = QVariant( pm.toImage() ); } } Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser, QVariant::fromValue< QVariantMap >( playInfo ) ); }
QPixmap SxButton::recolorPixmap(const QPixmap& pixmap, int _r, int _g, int _b) { QImage image = pixmap.toImage(); QImage alpha = image.alphaChannel(); for (int y = 0; y < image.height(); y++) { for (int x = 0; x < image.width(); x++) { QRgb color = image.pixel(x,y); int r = qRed(color); int g = qGreen(color); int b = qBlue(color); r+= _r; g+= _g; b+= _b; if (r<0) r=0; else if (r>=256) r=255; if (g<0) g=0; else if (g>=256) g=255; if (b<0) b=0; else if (b>=256) b=255; color = QColor(r,g,b).rgb(); image.setPixel(x,y,color); } } image.setAlphaChannel(alpha); return QPixmap::fromImage(image); }
QColor KColorDialog::grabColor(const QPoint &p) { #ifdef Q_WS_X11 // we use the X11 API directly in this case as we are not getting back a valid // return from QPixmap::grabWindow in the case where the application is using // an argb visual Window root = RootWindow(QX11Info::display(), QX11Info::appScreen()); // XImage *ximg = XGetImage(QX11Info::display(), root, p.x(), p.y(), 1, 1, -1, ZPixmap); // unsigned long xpixel = XGetPixel(ximg, 0, 0); // XDestroyImage(ximg); XColor xcol; // xcol.pixel = xpixel; xcol.flags = DoRed | DoGreen | DoBlue; // XQueryColor(QX11Info::display(), // DefaultColormap(QX11Info::display(), QX11Info::appScreen()), // &xcol); return QColor::fromRgbF(xcol.red / 65535.0, xcol.green / 65535.0, xcol.blue / 65535.0); #else QWidget *desktop = QApplication::desktop(); QPixmap pm = QPixmap::grabWindow(desktop->winId(), p.x(), p.y(), 1, 1); QImage i = pm.toImage(); return i.pixel(0, 0); #endif }
//------------------------------------------------- QImage * ImageWriter::createImage ( time_t date, ImageWriterDialog &dial, int Winit, int Hinit) { QImage *image = NULL; int W = dial.getW (); int H = dial.getH (); if (dial.getResizeAfter() && (W!=Winit || H!=Hinit) ) { QPixmap *pixmap = terre->createPixmap (date, Winit, Hinit); if (pixmap) { QPixmap pixmap2 = pixmap->scaled (W, H, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); image = new QImage (pixmap2.toImage ()); delete pixmap; } } else { QPixmap *pixmap = terre->createPixmap (date, W, H); if (pixmap) { image = new QImage (pixmap->toImage ()); delete pixmap; } } return image; }
void Cover::setCoverPixmap(const QPixmap &pixmap) { Q_D(Cover); int radius = d->m_radius; QSize sz = size(); QPainter::CompositionMode mode = QPainter::CompositionMode_SourceIn; QPixmap destinationImage(sz); destinationImage.fill(Qt::transparent); QPainterPath path; path.addRoundRect(QRectF(0, 0, sz.width(), sz.height()), radius); QPainter bkPainter(&destinationImage); bkPainter.setRenderHint(QPainter::Antialiasing); bkPainter.setPen(QPen(Qt::white, 1)); bkPainter.fillPath(path, QBrush(Qt::red)); QPixmap backgroundImage = pixmap.scaled(sz, Qt::KeepAspectRatioByExpanding); QImage resultImage = QImage(sz, QImage::Format_ARGB32_Premultiplied); QPainter painter(&resultImage); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(resultImage.rect(), Qt::transparent); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawImage(0, 0, destinationImage.toImage()); painter.setCompositionMode(mode); painter.drawImage(0, 0, backgroundImage.toImage()); painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); painter.end(); d->m_Background = QPixmap::fromImage(resultImage); }
void QPdfEngine::drawPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr) { if (sr.isEmpty() || rectangle.isEmpty() || pixmap.isNull()) return; Q_D(QPdfEngine); QBrush b = d->brush; QRect sourceRect = sr.toRect(); QPixmap pm = sourceRect != pixmap.rect() ? pixmap.copy(sourceRect) : pixmap; QImage image = pm.toImage(); bool bitmap = true; const int object = d->addImage(image, &bitmap, pm.cacheKey()); if (object < 0) return; *d->currentPage << "q\n/GSa gs\n"; *d->currentPage << QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(), rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix)); if (bitmap) { // set current pen as d->brush d->brush = d->pen.brush(); } setBrush(); d->currentPage->streamImage(image.width(), image.height(), object); *d->currentPage << "Q\n"; d->brush = b; }
/** * Provides printing support of the plot image. * */ void ScatterPlotWindow::printPlot() { QPixmap pixmap; /* Initialize a printer*/ static QPrinter *printer = NULL; if (printer == NULL) printer = new QPrinter; printer->setPageSize(QPrinter::Letter); printer->setColorMode(QPrinter::Color); QPrintDialog printDialog(printer,(QWidget *)parent()); if (printDialog.exec() == QDialog::Accepted) { /* Get display widget as a pixmap and convert to an image*/ pixmap = QPixmap::grabWidget(p_plot); QImage img = pixmap.toImage(); /* C++ Gui Programming with Qt, page 201*/ QPainter painter(printer); QRect rect = painter.viewport(); QSize size = img.size(); size.scale(rect.size(),Qt::KeepAspectRatio); painter.setViewport(rect.x(),rect.y(), size.width(),size.height()); painter.setWindow(img.rect()); painter.drawImage(0,0,img); } }
void ribi::QtBoenkenMainDialog::Paint( QPixmap& pixmap, const unsigned char r, const unsigned char g, const unsigned char b, const unsigned char a) { const int width = pixmap.width(); const int height = pixmap.height(); QImage image = pixmap.toImage(); assert(image.bytesPerLine() / width == 4 && "Assume there are 4 bytes per pixel"); for (int y=0; y!=height; ++y) { unsigned char * const line = static_cast<unsigned char *>(image.scanLine(y)); for (int x=0; x!=width; ++x) { line[x*4+3] = a; //Alpha value line[x*4+2] = r; //Red line[x*4+1] = g; //Green line[x*4+0] = b; //Blue } } pixmap = pixmap.fromImage(image); }
// return pixmap for a given zoom != 100 QPixmap * get_pixmap(QString path, double zoom) { QPixmap * px = get_pixmap(path); if (px == 0) return 0; if (((int)(zoom * 100)) == 100) return px; QMap<void*,QPixmap*> * d = DiagramScaledPixmap[path]; // != 0 intptr_t scaled_w = static_cast<intptr_t>(px->width() * zoom); void * k = (void *) scaled_w; QPixmap * scaled_px = d->value(k); if (scaled_px == 0) { QImage img = px->toImage().scaled(scaled_w, (int)(px->height() * zoom)); scaled_px = new QPixmap(); scaled_px->convertFromImage(img); d->insert(k, scaled_px); } return scaled_px; }
/* Test that vertical and horizontal mac-style scrollbars paint their entire area. */ void tst_MacGui::scrollbarPainting() { ColorWidget colorWidget; colorWidget.resize(400, 400); QSize scrollBarSize; QScrollBar verticalScrollbar(&colorWidget); verticalScrollbar.move(10, 10); scrollBarSize = verticalScrollbar.sizeHint(); scrollBarSize.setHeight(200); verticalScrollbar.resize(scrollBarSize); QScrollBar horizontalScrollbar(&colorWidget); horizontalScrollbar.move(30, 10); horizontalScrollbar.setOrientation(Qt::Horizontal); scrollBarSize = horizontalScrollbar.sizeHint(); scrollBarSize.setWidth(200); horizontalScrollbar.resize(scrollBarSize); colorWidget.show(); colorWidget.raise(); QTest::qWait(100); QPixmap pixmap = grabWindowContents(&colorWidget); QVERIFY(isContent(pixmap.toImage(), verticalScrollbar.geometry(), GuiTester::Horizontal)); QVERIFY(isContent(pixmap.toImage(), horizontalScrollbar.geometry(), GuiTester::Vertical)); }
void GraphicDeadEffect::draw(QPainter *painter) { QPoint offset; // Draw pixmap in device coordinates to avoid pixmap scaling; const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); if(_pix_size_x == 0) { // Initialisation _pix_size_x = pixmap.size().width(); _pix_size_y = pixmap.size().height(); _pixels_cleared = new bool*[_pix_size_x]; for(int i = 0 ; i < _pix_size_x ; ++ i) { _pixels_cleared[i] = new bool(_pix_size_y); } _timer.start(UPDATE_PERIOD); // Connect animation timer connect(&_timer, SIGNAL(timeout()), this, SLOT(updateAnimation())); } QImage img = pixmap.toImage(); painter->setWorldTransform(QTransform()); for(int i = 0 ; i < _pix_size_x ; i ++) { for(int j = 0 ; j < _pix_size_y ; j ++) { if(_pixels_cleared[i][j]) { img.setPixel(i, j, qRgb(0, 0, 0)); } } } painter->drawImage(offset, img); }
TRaster32P rasterFromQPixmap( QPixmap pixmap, bool premultiply, bool mirror) // no need of const& - Qt uses implicit sharing... { QImage image = pixmap.toImage(); return rasterFromQImage(image, premultiply, mirror); }
bool GraphicsContext3D::getImageData(Image* image, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, Vector<uint8_t>& outputVector) { UNUSED_PARAM(ignoreGammaAndColorProfile); if (!image) return false; QImage nativeImage; // Is image already loaded? If not, load it. if (image->data()) nativeImage = QImage::fromData(reinterpret_cast<const uchar*>(image->data()->data()), image->data()->size()).convertToFormat(QImage::Format_ARGB32); else { QPixmap* nativePixmap = image->nativeImageForCurrentFrame(); nativeImage = nativePixmap->toImage().convertToFormat(QImage::Format_ARGB32); } AlphaOp neededAlphaOp = AlphaDoNothing; if (premultiplyAlpha) neededAlphaOp = AlphaDoPremultiply; unsigned int packedSize; // Output data is tightly packed (alignment == 1). if (computeImageSizeInBytes(format, type, image->width(), image->height(), 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR) return false; outputVector.resize(packedSize); return packPixels(nativeImage.bits(), SourceFormatBGRA8, image->width(), image->height(), 0, format, type, neededAlphaOp, outputVector.data()); }
QImage makeShadow( const QPixmap& textPixmap, const QColor &bgColor ) { const int w = textPixmap.width(); const int h = textPixmap.height(); const int bgr = bgColor.red(); const int bgg = bgColor.green(); const int bgb = bgColor.blue(); int alphaShadow; // This is the source pixmap QImage img = textPixmap.toImage(); QImage result( w, h, QImage::Format_ARGB32 ); result.fill( 0 ); // fill with black static const int M = 5; for( int i = M; i < w - M; i++) { for( int j = M; j < h - M; j++ ) { alphaShadow = (int) decay( img, i, j ); result.setPixel( i,j, qRgba( bgr, bgg , bgb, qMin( MAX_OPACITY, alphaShadow ) ) ); } } return result; }
void GrDapView::imgItemAddScene(int id, QPixmap capa, bool isVisor, bool resizeScene) { if( resizeScene ) scene->setSceneRect(0, 0, capa.width() + scene_space, capa.height() + scene_space); GrDapImgItem *imagen = new GrDapImgItem(capa); imagen->setPixmap(capa); imagen->setZValue(id); imagen->setVisible(true); imagen->setIsVisor(isVisor); listItems.insert(id, imagen); imgItemCentrar(id); imgItemRotar(id, 0); if( isVisor ) { imagen->setFlag(QGraphicsItem::ItemIsMovable, true); visor_img = capa.toImage(); connect(imagen, SIGNAL(posChanged(QPointF,bool)), this, SLOT(posVisorChanged(QPointF,bool))); emit posVisorChanged(imagen->pos(), isVisor); } scene->addItem(imagen); if( resizeScene ) { horizontalScrollBar()->setValue(horizontalScrollBar()->maximum()/2); verticalScrollBar()->setValue(verticalScrollBar()->maximum()/2); } }
QPixmap IconLoader::invert(QPixmap pmap) { QImage img = pmap.toImage().convertToFormat(QImage::Format_ARGB32); for (int y = 0; y < img.height(); ++y) { for (int x = 0; x < img.width(); ++x) { QRgb rgba = img.pixel(x, y); QColor colour = QColor (qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba)); int alpha = colour.alpha(); if (colour.saturation() < 5 && colour.alpha() > 10) { colour.setHsv(colour.hue(), colour.saturation(), 255 - colour.value()); colour.setAlpha(alpha); img.setPixel(x, y, colour.rgba()); } } } pmap = QPixmap::fromImage(img); return pmap; }
/* On linux the function p.mask() screws up, so a new one is made. On windows the standard one is fine */ static QBitmap mask(const QPixmap &p) { #if !defined(WIN32) && !defined(WIN64) /* * This code is for when borders aren't alpha'd properly (all the move types battle buttons needs to have their border alpha'd) * Of course the problem only occurs on linux */ QImage image = p.toImage(); for (int i = 0; i < image.width(); i++) { for (int j = 0; j < image.height(); j++) { image.setPixel(i,j, qAlpha(image.pixel(i,j)) <= 0x0f ? 0x0 : 0xffffffff); } } return QBitmap::fromData(p.size(), image.bits()); /* Use this code when you've removed any non-alpha border from all images called by qimagebutton (including battle buttons, challenge window and menu, and pokedex arrows) return QBitmap::fromData(p.size(), p.toImage().bits()); */ #else return p.mask(); #endif }
void histograma::setDatos(QPixmap pixmap){ QRgb pixel; int red, green,blue,gray; R =new QVector<double>(256); G =new QVector<double>(256); B =new QVector<double>(256); Gr =new QVector<double>(256); X= new QVector<double>(256); for (int i=0; i<256; ++i) X->operator [](i)=i; for(int x=0;x<pixmap.width();x++){ for(int y=0;y<pixmap.height();y++){ pixel=pixmap.toImage().pixel(x,y); red=qRed(pixel); green=qGreen(pixel); blue=qBlue(pixel); gray=(red * 11 + green * 16 + blue * 5)/32; R->operator [](red)++; G->operator [](green)++; B->operator [](blue)++; Gr->operator [](gray)++; } } Dibujar(ui->customPlot); ui->customPlot->replot(); }