Draw with alpha atop of QImage from blob
-
Halo everyone,
I need to draw a few things atop of
QImage
created fromunsigned char*
array.
But drawing doesn't respect alpha channel and anti-aliasing.void processFrame(unsigned char* frameData, int w, int h, int lineSize) { QImage frameImage(frameData, w, h, lineSize, QImage::Format_ARGB32); QPainter p(&frameImage); p.setRenderHint(QPainter::Antialiasing); QColor c(255, 255, 255, 150); // white and translucent p.setPen(c); p.setBrush(c); p.drawRoundedRect(rectX, rectY, rectW, rectH, rectW / 35.0, rectH / 35.0); p.end(); }
I get only white, opaque rectangle.
And for the record - this function is called from C code through C++ wrapper - so there is noQGuitApplication
- if it matters.
Did I miss something? -
Halo everyone,
I need to draw a few things atop of
QImage
created fromunsigned char*
array.
But drawing doesn't respect alpha channel and anti-aliasing.void processFrame(unsigned char* frameData, int w, int h, int lineSize) { QImage frameImage(frameData, w, h, lineSize, QImage::Format_ARGB32); QPainter p(&frameImage); p.setRenderHint(QPainter::Antialiasing); QColor c(255, 255, 255, 150); // white and translucent p.setPen(c); p.setBrush(c); p.drawRoundedRect(rectX, rectY, rectW, rectH, rectW / 35.0, rectH / 35.0); p.end(); }
I get only white, opaque rectangle.
And for the record - this function is called from C code through C++ wrapper - so there is noQGuitApplication
- if it matters.
Did I miss something?@SeeLook said in Draw with alpha atop of QImage from blob:
Did I miss something?
Yes :)
QImage::Format_ARGB32
Have a look here....
QColor c(255, 255, 255, 150); // white and translucent
... and then look back here again :)
Are you sure the format is correct?
See here:
-
@Pl45m4 thanks for the answer.
I wish it would be so easy...
First of all, whatever blob data format is,QColor
isQColor
and its constructor takes arguments in that exact order (R, G, B, A).
And I can get blob data in that format (RGBA8888), I've tried already - the same result.When I tried with color (127, 127, 127, 127) - the same, no transparency at all.
Also there is no anti-aliasing - drawing doesn't react with underlying pixels.
And I tested thisQImage
instance - pixel colors are as they should be - it looks likeQPianter
has problem with that painting device. -
Have you tried different Composition Modes?
-
Have you tried different Composition Modes?
Yes.
And it works when it comes to cover source (rectangle) but not for blending with blob image pixels. -
QPainter painter(this);
Maybe here is the thing... There is no any
this
.
this
is used whenQPainter
is used in GUI app - it isQWidget
then orQGraphicsSceneItem
or so.Here is only a library which uses bare
QImage
which isQPiantDevice
forQPainter
. -
QPainter painter(this);
Maybe here is the thing... There is no any
this
.
this
is used whenQPainter
is used in GUI app - it isQWidget
then orQGraphicsSceneItem
or so.Here is only a library which uses bare
QImage
which isQPiantDevice
forQPainter
. -
@JoeCFD - over pixels of
QImage
from blob/raw data.
And those raw pixels are changed - as example image shows butQPainter
doesn't react with original ones - just overwrites them. -
@JoeCFD
In example image I attached before - background is pink and rectangle is as it is.
And I also tried to draw that entire image again into painter:p.drawImage(0, 0, frameImage);
then draw that rectangle atop of all - still the same difference - no alpha.