Home All Groups Group Topic Archive Search About

TransparentBlt and Autoredraw issues (refresh isnt solving it)

Author
10 Mar 2006 3:02 AM
jroozee@gmail.com
I am having a very strang issue. I have a picture box with Autoredraw
set to true. I am clearing the picture box and re-writing data to it
about 5 times a second (a real time graph) .

I .Cls it, then I draw some data to it using .Print  and .Line  and
..PaintPicture. Everything works great!

Now, I am trying to use TransparentBlt to paint a image with a
transparent bg to the picturebox. It appears for a split second and
then disappears.

My code using the TransparentBlt workds fine for as long that is the
ONLY thing I am doing with the picturebox. But when I am first writing
tons of other data to the picturebox first, is when I am having issues.

I've tried to .Refresh or .Picture = .Image before and/or after calling
the TransparentBlt, but nothing works.

Any ideas?

Anyone?


Jason Roozee

Author
10 Mar 2006 3:56 AM
Randy Birch
After the blt try picture1.picture = picture1.image.

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




<jroo***@gmail.com> wrote in message
news:1141959736.096917.126820@i40g2000cwc.googlegroups.com...
I am having a very strang issue. I have a picture box with Autoredraw
set to true. I am clearing the picture box and re-writing data to it
about 5 times a second (a real time graph) .

I .Cls it, then I draw some data to it using .Print  and .Line  and
..PaintPicture. Everything works great!

Now, I am trying to use TransparentBlt to paint a image with a
transparent bg to the picturebox. It appears for a split second and
then disappears.

My code using the TransparentBlt workds fine for as long that is the
ONLY thing I am doing with the picturebox. But when I am first writing
tons of other data to the picturebox first, is when I am having issues.

I've tried to .Refresh or .Picture = .Image before and/or after calling
the TransparentBlt, but nothing works.

Any ideas?

Anyone?


Jason Roozee
Author
10 Mar 2006 12:50 PM
Mike D Sutton
Show quote Hide quote
>I am having a very strang issue. I have a picture box with Autoredraw
> set to true. I am clearing the picture box and re-writing data to it
> about 5 times a second (a real time graph) .
>
> I .Cls it, then I draw some data to it using .Print  and .Line  and
> .PaintPicture. Everything works great!
>
> Now, I am trying to use TransparentBlt to paint a image with a
> transparent bg to the picturebox. It appears for a split second and
> then disappears.
>
> My code using the TransparentBlt workds fine for as long that is the
> ONLY thing I am doing with the picturebox. But when I am first writing
> tons of other data to the picturebox first, is when I am having issues.
>
> I've tried to .Refresh or .Picture = .Image before and/or after calling
> the TransparentBlt, but nothing works.

How are you drawing to the picture box, i.e. which DC are you rendering to?
If you're using the GetDC() API call on the picture box's window handle and
rendering to that, then this will draw to the control's surface directly but
not to the back-buffer created by controls with the AutoRedraw property
enabled.  If this is the case then simply change your code to use the .hDC
property of the picture box to draw onto, otherwise post your code; there's
no reason why it shouldn't be working from what you're described.
Are you making any other GDI calls to the picture box at any stage in your
application or is TransparentBlt() the only one?  Also, are you setting any
properties of the picture box other than the AutoRedraw property which could
be affecting GDI output?
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
10 Mar 2006 5:53 PM
jroozee@gmail.com
Thanks! That was it! And also, I was not calling DeleteObject in my API
I was using to create the image, so I was having memory leaks.

Jason
Author
10 Mar 2006 1:15 PM
Mike Williams
<jroo***@gmail.com> wrote in message
news:1141959736.096917.126820@i40g2000cwc.googlegroups.com...

> My code using the TransparentBlt workds fine for as long that is
> the ONLY thing I am doing with the picturebox. But when I am
> first writing tons of other data to the picturebox first, is when I am
> having issues.

Should work fine, unless you're doing something out of the ordinary. Is all
this drawing (all of it) in the same routine, or in different routines? Try
the following and see if it works for you (replace the hard coded picture to
a jpeg or whatevber that exists on your own machine). I've deliberately
repeatedly used PaintPicture to stretch the background into the picbox just
to slow things down to see if there are any problems, but it works fine
here. The code should draw (stretch to fit) a jpeg as the background and
then draw soem circles on top of that and then TransparentBlt some text on
top. It should do this about five times a second. Check it out and post back
if you still have problems.

Mike

Option Explicit
Private Declare Function TransparentBlt Lib "msimg32.dll" _
  (ByVal hdc As Long, _
  ByVal x As Long, ByVal y As Long, _
  ByVal nWidth As Long, ByVal nHeight As Long, _
  ByVal hSrcDC As Long, _
  ByVal xSrc As Long, ByVal ySrc As Long, _
  ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, _
  ByVal crTransparent As Long) As Boolean
Private Declare Function LineTo Lib "gdi32" _
  (ByVal hdc As Long, _
  ByVal x As Long, ByVal y As Long) As Long
Private p1 As StdPicture

Private Sub Form_Load()
Picture1.AutoRedraw = True
With Picture2
  .AutoRedraw = True
  .Visible = False
  .Move 0, 0, Picture1.Width, Picture1.Height
  .BackColor = vbWhite
  .Font.Name = "Times New Roman"
  .Font.Size = 36
  .ForeColor = vbRed
Picture2.Print " This is being"
Picture2.Print " blit using"
Picture2.Print " TransparentBlt"
End With
Timer1.Interval = 200
Timer1.Enabled = True
Set p1 = LoadPicture("c:\tulips1600x1200.jpg")
End Sub

Private Sub Timer1_Timer()
Dim wide As Long, high As Long, n As Long
wide = Picture1.ScaleWidth
high = Picture1.ScaleHeight
Picture1.Cls
Picture1.PaintPicture p1, 0, 0, wide, high
For n = 1 To 100
Picture1.Circle (Rnd * wide, Rnd * high), Rnd * wide / 4, Rnd * &HFFFFFF
Next n
TransparentBlt Picture1.hdc, 0, 0, wide, high, _
  Picture2.hdc, 0, 0, wide, high, vbWhite
End Sub