void Adafruit_SSD1306::drawBitmap(int x, int y, const unsigned char *bitmap, int w, int h, QColor color){ //check if size is valid if(w%8 != 0 || h%8 != 0){ qWarning() << "Width and Height of bitmap shold be multiply of 8 (widht % 8 = 0)"; return; } //GENERATE PIXMAP FROM BITMAP QPixmap temp(w,h); temp.fill(Qt::transparent); QPainter tempPaint(&temp); tempPaint.setPen(color); for(int i = 0; i < w*h; i++){ bool value = (bitmap[i/8] >> (7-(i%8))) & 0x01 == 0x01 ? true : false; if(value){ tempPaint.drawPoint(i%w,i/w); } } QPainter p(writeBuffer); p.drawPixmap(x,y,w,h,temp); }
void CropAction::perform(ImageArea *area, bool prev) { area->applySelection(); if (prev) { QPainter paint(area->preview); paint.setBrush(QBrush(QColor(0, 0, 0, 128))); paint.setPen(Qt::NoPen); paint.drawRect(QRect(0, 0, rect->x(), area->image->height())); paint.drawRect(QRect(rect->x() + rect->width(), 0, area->image->width() - rect->x() - rect->width(), area->image->height())); paint.drawRect(QRect(rect->x(), 0, rect->width(), rect->y())); paint.drawRect(QRect(rect->x(), rect->y() + rect->height(), rect->width(), area->image->height() - rect->y() - rect->height())); } else { QImage *newImage = new QImage(rect->width(), rect->height(), QImage::Format_ARGB32); newImage->fill(0); QPainter tempPaint(newImage); tempPaint.drawImage(-rect->x(), -rect->y(), *area->image); tempPaint.end(); //Swap the two images area->painter->end(); area->image->swap(*newImage); area->painter->begin(area->image); delete newImage; if (area->selection != 0) { area->selection->translate(-rect->x(), -rect->y()); } } }
void CanvasSizeAction::perform(ImageArea *area, bool prev) { area->applySelection(); QImage *img; QPainter *paint; if (prev) { img = area->preview; paint = new QPainter(img); } else { img = area->image; paint = area->painter; } QImage *newImg = new QImage(width, height, QImage::Format_ARGB32); newImg->fill(0); QPainter tempPaint(newImg); //Calculate the position to draw the image. int x, y; switch (horAnchor) { case anchorLeft: x = 0; break; case anchorMiddle: x = (width - img->width()) / 2; break; case anchorRight: x = width - img->width(); } switch (verAnchor) { case anchorTop: y = 0; break; case anchorMiddle: y = (height - img->height()) / 2; break; case anchorBottom: y = height - img->height(); } tempPaint.drawImage(x, y, *img); tempPaint.end(); //Swap the two images paint->end(); img->swap(*newImg); paint->begin(img); delete newImg; if (prev) { delete paint; } }