excuse my anger, but I AM angry!! been playing with this for 2 days and still doesnt work!
This is what my sample app is supposed to do: when the user moves the mouse, it's suppose to draw an alpha blended rectangle over the form's background image. As the mouse moves, the rectangles gets larger or smaller, depending on the mouse position on the form. The problem is that it FLICKERS and it doesnt WORK!!!!!
Here's what it SHOULD look like:
but it doesnt work. here's my code:
VB Code:
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim gr As Graphics = Me.CreateGraphics
Dim rgn As New Region(New Rectangle(0, 20, e.X, Me.ClientSize.Height - 45))
Dim myBrush As New SolidBrush(Color.FromArgb(50, 0, 0, 0))
' THIS EVIL MAKES IT FLICKER!!!!!
' I cant use gr.Clear because it erases the background image
Me.Invalidate()
gr.FillRegion(myBrush, rgn)
gr.Dispose()
End Sub
I have the code in a project, it would be nice if you download it, because you can clearly see what I mean by flicker when you run the app
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Dim bmp As New Bitmap(Me.Width, Me.Height)
Me.BackgroundImage = bmp
Dim G As Graphics
G = G.FromImage(bmp)
G.Clear(Color.Beige)
this sets a bitmap to the form. then you will be drawing on the bitmap. also it keeps it persistant. if you notice when you put another window infront of the one your drawing on, what you draw is messed up, or when you minimize then restore. this will fix that. this is the prefered way for persistant graphics
The Programmers Credo -
Protect dumb-ass from himself.
well it doesnt work, and you said "it keeps it persistant". I DONT want this if you run the app you will see. I dont want autoredraw, I just want the pic to be drawn as the mouse is moving
and also your code does the same thing, but it also erases the background image which I had (because you use g.clear)
just download the app and move the mouse on the screen. I want that rectangle to look like the screen shot that I have posted (with the same opacity, and without flickers )
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
The problem is with the Region, seems like the rectangle isn't moving along with the mouse but is staying stuck to the left edge of the form. No idea why, the docs for Rectangle seem to show you're setting the upper left corner correctly (e.X being where the mouse is). Maybe the docs are wrong?
...
ah the docs are just confusing whee, distraction from my heinous triggerfest!
...
Try this:
Code:
Dim gr As Graphics = Me.CreateGraphics
'Dim rgn As New Region(New Rectangle(0, 20, e.X, Me.ClientSize.Height - 80))
Dim rgn As New Region(New Rectangle(e.X, e.Y, 1, 70))
Dim myBrush As New SolidBrush(Color.FromArgb(50, 0, 0, 0))
gr.FillRegion(myBrush, rgn)
gr.Dispose()
Me.Invalidate makes it clear as you draw, you didn't want that did you? This got me something sorta close to what your picture showed...
Last edited by Slow_Learner; Sep 30th, 2002 at 12:31 AM.
Originally posted by Slow_Learner The problem is with the Region, seems like the rectangle isn't moving along with the mouse but is staying stuck to the left edge of the form. No idea why, the docs for Rectangle seem to show you're setting the upper left corner correctly (e.X being where the mouse is). Maybe the docs are wrong?
...
ah the docs are just confusing whee, distraction from my heinous triggerfest!
...
Try this:
Code:
Dim gr As Graphics = Me.CreateGraphics
'Dim rgn As New Region(New Rectangle(0, 20, e.X, Me.ClientSize.Height - 80))
Dim rgn As New Region(New Rectangle(e.X, e.Y, 1, 70))
Dim myBrush As New SolidBrush(Color.FromArgb(50, 0, 0, 0))
gr.FillRegion(myBrush, rgn)
gr.Dispose()
Me.Invalidate makes it clear as you draw, you didn't want that did you? This got me something sorta close to what your picture showed...
well thanks for helping, but it didnt help
well, the rectangle is supposed to be stock like that.... I'm not really making an app that does this, I just wrote this for a sample. The rectangle is being resized correctly, it just flickers. If I remove the invalidate, it will draw a number of rectangles on top of each other and I will no longer have an alpha blended picture.
hope this makes sense
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
I am not a guru with images, so I don't know what alpha blended image means. So don't get mad if this doesn't help. What I would do is put another rectangle over the old one the same color as the background (or fill it with the background image...I have some code for that I do believe, just would have to find it in one of the books I have).
Originally posted by hellswraith I am not a guru with images, so I don't know what alpha blended image means. So don't get mad if this doesn't help. What I would do is put another rectangle over the old one the same color as the background (or fill it with the background image...I have some code for that I do believe, just would have to find it in one of the books I have).
I'd be happy to see any code, MIGHT help anyways
alpha blending-> see the picture, you can see THROUGH the rectangle, it's not compeletly visible. that's what I mean.
the problem is that if I draw another rectangle OVER that, the transparency changes (alpha blending) and it will have a different alpha (get's opaque very fast).
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
I see what you mean - Well, the problem with .Invalidate is that it invokes .Paint, which makes the background of your form overlay what you have painted, which causes the flicker. Maybe there's a way to get a brush to not re-draw over an area you have already drawn (doesn't look like a really simple way to me).
Originally posted by Slow_Learner I see what you mean - Well, the problem with .Invalidate is that it invokes .Paint, which makes the background of your form overlay what you have painted, which causes the flicker. Maybe there's a way to get a brush to not re-draw over an area you have already drawn (doesn't look like a really simple way to me).
vb6 had a very nice way, I tried upgrading vb6 code to vb.net... but it doesnt upgrade those parts
in vb6 you could change the drawmode so that if you draw twice on the same thing, it would erase that area. it was vbXorPen, or something like that. It doesnt exist in vb.net I guess. But there HAS to be away to do this! if .NET is so powerful and GDI+ is so "cool", there should be a way!
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
There is a way, and I will try to find the code to do this for you. I now understand your problem more. Give me some time because I am really tired right now and need sleep. Got to get up in 5 hours. I will try to find it tomorrow afternoon, if you haven't already solved it.
Dim myBrush As New SolidBrush(Color.FromArgb(50, 0, 0, 0))
Dim Point1 As New PointF(0.0F, 20.0F)
Dim Point2 As New PointF(0.0F, 170.0F)
Dim Point3 As New PointF(e.X, 20.0F)
Dim Point4 As New PointF(e.X, 170.0F)
Dim arrBoxPoints As PointF() = {Point1, Point2, Point3, Point4}
Dim newFillMode As FillMode = FillMode.Alternate
gr.FillPolygon(myBrush, arrBoxPoints)
gr.Dispose()
Ok, I was looking around (so much for sleep tonight), and maybe these can get you started. I know that they are in C#, but right now it is easier to find C# code than VB.Net. Expecially in the graphics area because of all the C++ people that have been doing it for years can easily use C# and hence have produced more sample code.
There is plenty of examples over at C# corner of a lot of different things with the GDI+. If you go there, there is a link for a GDI+ section that has a lot of demos.
I ended up using regions and combining them and those kinda stuff ....
it's a REALLY messy way to code, but it WORKS!!!!!!!
I bet there is a better way to do this though.... I'll write an example in a few mins
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
naah, I'm not gunno write an example... too confusing
here's a part of my code anyways. It's supposed to highlight a part of a ruler control that I made for my drawing program.
VB Code:
' ...........
Dim curRgn, drawRgn, cleanupRgn, tmpRgn As Region
curRgn = getRgn(startP, curP)
tmpRgn = lastRgn.Clone()
tmpRgn.Intersect(curRgn)
' Highlighting the other side
If isRegionEmpty(tmpRgn) Then
cleanupRgn = lastRgn
drawRgn = curRgn
Me.Invalidate(cleanupRgn)
HighLight(drawRgn)
ElseIf regionLen(curRgn) < regionLen(lastRgn) Then
cleanupRgn = lastRgn.Clone
cleanupRgn.Exclude(curRgn)
Invalidate(cleanupRgn)
ElseIf regionLen(curRgn) <> regionLen(lastRgn) Then
drawRgn = curRgn.Clone()
drawRgn.Exclude(lastRgn)
HighLight(drawRgn)
End If
lastP = curP
lastRgn = curRgn
'.....
End Sub
Private Function isRegionEmpty(ByVal rgn As Region) As Boolean
Dim gr As Graphics = Me.CreateGraphics()
Return rgn.IsEmpty(gr)
End Function
Private Function regionLen(ByVal rgn As Region) As Integer
Dim gr As Graphics = Me.CreateGraphics()
Dim rectF As RectangleF = rgn.GetBounds(gr)
Return CInt(rectF.Width)
End Function
here's what is looks like :
Thanks hellswraith, I took a look at some of those examples in the morning, I couldnt find anything that would help me.... Thanks SlowLearner for the links
I'm still wondering how else I could do this though. My way is pretty messed up, although it works fine
Last edited by MrPolite; Sep 30th, 2002 at 04:51 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Glad you figured it out. I am out of town right now and thought I had the book with me that had an example of how to do this, but I don't. I have every other .net book but that one. Glad you got it working, even if it isn't pretty.