Alpha Blend Rectangle

ebbinger_413

Member
Joined
Apr 11, 2008
Messages
6
Programming Experience
1-3
I am working on a skinning application and am having a small issue with alpha blending.

I am looking to draw a rectangle onto an image that will be blended using alpha blending....

Here is the code i have been attempting to use...

VB.NET:
Dim bgup As Image = My.Resources.bgUp
        Dim info As Graphics = Me.CreateGraphics
        info.Clear(Me.BackColor)
        info.DrawImage(bgup, 0, 0, bgup.Width, bgup.Height)
        info.FillRectangle(New SolidBrush(Color.FromArgb(30, 0, 0, 255)), 10, 10, 200, 200)
        info.Dispose()

Now i would prefer to be able to either edit the image and add the rectangle so i can easily set a picture control to the edited image. But i can do as the code is trying to do above and simply draw the image to the position i need instead of using a control.

The problem with the code above is that i am not sure if it is actually drawing the image. I have several other images and controls on the form and i believe it is being drawn behind the other stuff. But cant be sure.

Any ideas ? as the code above correct to draw a rectangle with alpha blending onto an image and display that image ? Is there a way i can get the image to "send to front" ?
 
Don't draw with CreateGraphics. Either use a Paint event to paint a control dynamically, or draw to a bitmap and display that as Image/BackgroundImage.
 
drawing onto a bitmap seems like a more convienant way to do what i am trying to do...

so would i :

VB.NET:
dim bgUp as bitmap = my.resources.bgUp
bgUp.fillrectangle(solidbrush(30,0,0,255)), 10,10,10,10)
pic_bgUp.backgroundimage = bgUp

but now how would i draw my alpha blended rectangle onto the image ?

im pretty sure that this line

bgUp.fillrectangle(solidbrush(30,0,0,255)), 10,10,10,10)

wont work because fillrectangle isnt part of bitmap only graphics . . .
 
Draw to the bitmap with a Graphics instance create with FromImage method.
VB.NET:
dim bgUp as bitmap = my.resources.bgUp
Dim g As Graphics = Graphics.FromImage(bgup)
'use the Graphics methods to Draw... Fill... etc
g.Dispose()
pic_bgUp.backgroundimage = bgUp
 
Back
Top