Draw a Gradient with Transparency [ALPHA] with BitBlt
Hi,
Ok I do have a function, with BitBlt where it can draw Gradients, but its only from one colour to another. So e.g. From Red to Green.
But how can I make it go from Red to Tranparency - [ALPHA] ?
Can bitblt know how to not fully draw the pixel colour but vary its alpha level ?
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
AlphaBlend API Might be helpful, but can you post the code you use to draw a gradient with Bitblt? maybe it can be modified to do you need.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
some1uk03
Did you find any solution to this issue? I'm trying to make this work myself, but no luck so far..
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
Okay this is an older thread but...
BitBlt can handle a variety of bitwize operations but it cannot handle a graded transparency, AlphaBlend as jcis mentions can.
GradientFill Api can create a gradient with an alpha channel.
This is not something I have done but I am fairly confident the steps you would take is...
Create a 32bit DIB (or preferably DDB if available)
Use GradientFill to render the alpha gradient to the DIB/DDB.
Use Alphablend to render the DIB/DDB to the target device.
Although GradientFill supports alpha channels I don't think it can actually alphablend.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
Quote:
Originally Posted by Milk
Use Alphablend to render the DIB/DDB to the target device.
Ok.. I guess what I'm after, is to have a translucent to opaque gradient form. Such that the gradient goes from one color to translucent. The point beeing to see the background behind the form, not the form itself. Obviously different also from the normal form opacity, which is uniform over the whole form.
Trying to alphablend gives me only a blend with the form background color. Even if it's sat on transparency key, the alphablend will still be between the picture and the background.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
Quite an old thread this one, but I'll post the solution up tomorrow morning, because I'm on another machine now.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
Awsome. Looking forward to that :)
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
I'm looking forward to see how some1uk03 did resolve this. What you are wanting is in a way quite different from the original question. It's one thing rendering an image with an alpha channel, it's another creating transparent windows.
SetLayeredWindowAttributes can be used for a semi transparent windows but it can't do a gradient as such (i don't think.)
I'm sure there is a way I just don't know what it is.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
I am curious also.
SetLayeredWindowAttributes can make the form semi-transparent as mentioned, but it won't create the desired effect I fear. This is because if you do a semi-translucent gradient over the form, visually, it will go from the gradient color to the form's backcolor since the far end of the gradient will blend to the form background. SetLayeredWindowAttributes will then show this artifact also.
So, an obvious solution would seem to use UpdateLayeredWindow which can perfectly satisify the requirement. But there is one major downside. Any window using that API cannot support child controls (no buttons, textboxes, etc). Though the form can contain these, they will never be seen, though they are there and active/clickable. This is a major issue.
The most common workaround is to use 2 windows: 1 with just the background, using UpdateLayeredWindows. The other contains just controls and a color to be used with SetLayeredWindowAttributes' transparency key. These 2 windows are then overlayed with each other. Though this looks perfect, the issues come when moving one and keeping the other moving in-sync. Depending on PC speed, choppiness is common.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
yes LaVolpe u r absolutely right i also had worked around on this issue and sync of two layers always create problem and the solution is to hide window contents while dragging.
Re: Draw a Gradient with Transparency [ALPHA] with BitBlt
Milk & LaVolpe let your curiosity end : )
Quote:
Ok.. I guess what I'm after, is to have a translucent to opaque gradient form. Such that the gradient goes from one color to translucent.
Well I guess I hadn't read that properly, but its not a Translucent form that I needed in my original proble, but rather a function which returns the ALPHA value of another colour:
Code:
Private Function BlendColor(ByVal oColorFrom As OLE_COLOR, _
ByVal oColorTo As OLE_COLOR, _
Optional ByVal Alpha As Long = 128) As Long
Dim lCFrom As Long
Dim lCTo As Long
Dim lSrcR As Long
Dim lSrcG As Long
Dim lSrcB As Long
Dim lDstR As Long
Dim lDstG As Long
Dim lDstB As Long
lCFrom = oColorFrom
lCTo = oColorTo
lSrcR = lCFrom And &HFF
lSrcG = (lCFrom And &HFF00&) \ &H100&
lSrcB = (lCFrom And &HFF0000) \ &H10000
lDstR = lCTo And &HFF
lDstG = (lCTo And &HFF00&) \ &H100&
lDstB = (lCTo And &HFF0000) \ &H10000
BlendColor = RGB(((lSrcR * Alpha) / 255) + ((lDstR * (255 - Alpha)) / 255), _
((lSrcG * Alpha) / 255) + ((lDstG * (255 - Alpha)) / 255), _
((lSrcB * Alpha) / 255) + ((lDstB * (255 - Alpha)) / 255))
End Function
However, I do still have something In mind.. but Ill get back to this thread soon.