Flickering Images
Flickering Images
Flickering Images
Flickering Images
Flickering Images
Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images
Flickering Images Flickering Images
Flickering Images
Go Back  Xtreme Visual Basic Talk > > > Flickering Images


Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2005, 04:51 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Angry Flickering Images


Hi again.

Since using transparency on my images, any time I tell an image to move, it flickers horrendously. Is there any way to stop this?

Help would be much appreciated

I figured I might need bitBlt, but this has only started happening since I used transparency on my images
Reply With Quote
  #2  
Old 07-14-2005, 08:54 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

What kind of transparency?
What kind of images?
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 07-14-2005, 09:08 PM
EOB84 EOB84 is offline
Regular
 
Join Date: May 2003
Posts: 76
Default

If you are using the image control there is no way to stop your image from flikering. Use the picturebox control and turn auto redraw on. if you really need transparency you will have to use BIBLT.
Reply With Quote
  #4  
Old 07-15-2005, 06:52 AM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Quote:
Originally Posted by passel
What kind of transparency?
Think of it this way... If I save the pictures in paint, I have to give the picture a rectangular shape with a background. This creates problems with a game because players want to see an image moving, not a box with a picture in.

Quote:
What kind of images?
Just a normal Image control which contains a picture (with transparency!). The picture falls down the screen and then returns to the top and fall again. The images themselves are "*.GIF" images.

Quote:
Originally Posted by EOB84
if you really need transparency you will have to use BIBLT.
I assume that's for movement? I can get transparency on all the other images, but if I tell the image to move, it flickers big time The problem has only started since I put transparency on the pictures using photoshop. The things moved before (as a whole block) with very minimal flickering but now there are horrendous black flashes within the area.
__________________
Bool isStupid = True

Last edited by Norm; 07-15-2005 at 07:13 AM.
Reply With Quote
  #5  
Old 07-15-2005, 09:42 AM
noi_max's Avatar
noi_maxFlickering Images noi_max is offline
Still asleep...

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: IronForge
Posts: 2,694
Default

Image controls are considered "lightweight" controls and are drawn on top of everything else.

Flicker is due to the image being redrawn without a 'blank' phase so as it is being redrawn in each 'frame' of movement the drawing process itself is visible - hence the flicker.

A picturebox has something called a seperate device context which allows the drawing to finish before it's displayed. This happens when the autoredraw property is set to true. The image is then drawn 'behind the scenes' and there is less flicker.

Unfortunately, picturebox controls do not have their own built in method to deal with transparency (like with transparent gif images) which leaves the VB programmer looking for other means of drawing 'sprites'.

Forms and pictureboxes with a device context can be drawn to in another way, known as BitBlt (Bit block transfer). BitBlt is simply a method of copying an image from one place to another, but there are some extra things you can do with the bits.

Drawing with BitBlt works really well for transparent sprites but it leaves the programmer with a little extra preperation. For example, masks need to be created in order for BitBlt to acheive a borderless effect. Also a backbuffer (like the picturebox's autoredraw) must be created to avoid flicker. This goes back to drawing behind the scenes as mentioned before.

The good news is that there is a ton of resources for drawing with BitBlt available to you that can get you there a lot faster.

Here are some good links to help you get started

BitBlt with transparency and masks tutorial
http://www.rookscape.com/vbgaming/GBeebe/bitblt.php

Newbie BitBlt and Backbuffer stuff
BitBlt demos

Another good BitBlt Tutorial
http://www.xtremevbtalk.com/showpost...10&postcount=9

Hope that helps!
__________________
~ Jason

Use [vb][/vb] tags when posting code :) || Search the forum and MSDN|| Check out the Posting Guidelines
Reply With Quote
  #6  
Old 07-15-2005, 10:15 AM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Thanks for that

Just discovered that the gifs flicker far more than ico files, so I'm using ico's for the moment. I will change them and use BitBlt later though (I have an eternal hatred for BitBlt - long story).
__________________
Bool isStupid = True
Reply With Quote
  #7  
Old 07-15-2005, 11:10 AM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Since you already had transparent Gifs, you might want to look at this thread (from post #3, on).
Since a Gif already has a transparent area, you don't have to create a mask, per se, you just load the Gif into a picturebox with a Black or White background, and copy the .Picture from that picturebox to a picturebox with the opposite color background (White or Black). You can then bitblt those two images with the correct raster op, to get transparency.
But of course, you have to restore the background area where you bitblt to when you move, so is not as convenient as using a control where VB will take care of fixing up the background.
There are several approaches you can take to restore the background.
1. Always redraw everything.
2. Save the portion of the background you're going to draw on, and restore it later (assumes a static background, or not worrying about multiple objects overlapping).
3. Keep the whole background in a separate buffer that you can use to restore from.
4. Use a picturebox control, and blit the background into your picturebox and draw your character on top, when ever you move the control. (Still a problem if you are going to have overlapping objects moving around).
5. There are no doubt other options, but the four above are the first that come to my mind.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #8  
Old 07-15-2005, 12:01 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Quote:
Originally Posted by passel
Since you already had transparent Gifs, you might want to look at this thread (from post #3, on).
Since a Gif already has a transparent area, you don't have to create a mask, per se, you just load the Gif into a picturebox with a Black or White background, and copy the .Picture from that picturebox to a picturebox with the opposite color background (White or Black). You can then bitblt those two images with the correct raster op, to get transparency.
But of course, you have to restore the background area where you bitblt to when you move, so is not as convenient as using a control where VB will take care of fixing up the background.
There are several approaches you can take to restore the background.
1. Always redraw everything.
2. Save the portion of the background you're going to draw on, and restore it later (assumes a static background, or not worrying about multiple objects overlapping).
3. Keep the whole background in a separate buffer that you can use to restore from.
4. Use a picturebox control, and blit the background into your picturebox and draw your character on top, when ever you move the control. (Still a problem if you are going to have overlapping objects moving around).
5. There are no doubt other options, but the four above are the first that come to my mind.
Thanks for your help (and all the rest of you guys)!!!

I think I'm going to put up with the flickering for a while. The simple reason for this is I'm just going to get confused otherwise with the pictures.

Curently, a random picture is being drawn to the picture box, so in effect we will have something along the lines of

Code:
picture1.picture = picture2.picture

And later in the code...

Code:
If (Rnd * 3) < 1 Then picture1.picture = picture3.picture Else picture1.picture = picture4.picture End If

Would this be a problem? Or could I make picture1 a blank with a white background, paint pictures 3 or 4 (depending) onto picture2 (with a black background) and then BitBlt picture1 and picture2?

Have I lost you here?
__________________
Bool isStupid = True
Reply With Quote
  #9  
Old 07-17-2005, 09:45 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Well, if you look at the code from that previous link, you should see that it would would probably work well with your use of pictures.

You would want two pictureboxes with their backcolors set. One set to White, and the other set to black.
Since you're using Picture1, let's make it a control array.
Code:
Private Sub Form_Load() Picture1(0).Backcolor = vbBlack 'Could set these in the IDE Picture1(1).Backcolor = vbWhite End Sub If (Fnd * 3) < 1 then Picture1(0).Picture = picture3.Picture Picture1(1).Picture = picture3.Picture else Picture1(0).Picture = picture4.Picture Picture1(1).Picture = picture4.Picture end if BitBlt me.hDC, X,Y,W,H,picture1(0).hdc,0,0,vbSrcPaint 'Paint the blackbackground BitBlt me.hDC, X,Y,W,H,picture1(1).hdc,0,0,vbSrcAnd 'And the whitebackground
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #10  
Old 07-18-2005, 06:46 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Quote:
Originally Posted by passel
Well, if you look at the code from that previous link, you should see that it would would probably work well with your use of pictures.

You would want two pictureboxes with their backcolors set. One set to White, and the other set to black.
Since you're using Picture1, let's make it a control array.
Code:
Private Sub Form_Load() Picture1(0).Backcolor = vbBlack 'Could set these in the IDE Picture1(1).Backcolor = vbWhite End Sub If (Fnd * 3) < 1 then Picture1(0).Picture = picture3.Picture Picture1(1).Picture = picture3.Picture else Picture1(0).Picture = picture4.Picture Picture1(1).Picture = picture4.Picture end if BitBlt me.hDC, X,Y,W,H,picture1(0).hdc,0,0,vbSrcPaint 'Paint the blackbackground BitBlt me.hDC, X,Y,W,H,picture1(1).hdc,0,0,vbSrcAnd 'And the whitebackground
Thanks for that!!! However, this will paint a transparent image to the target. There is still the big grey box around the picture.

God I'm such a n00b at BitBlt
__________________
Bool isStupid = True
Reply With Quote
  #11  
Old 07-18-2005, 07:09 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

If the pictures were transparent gifs, then the result should be transparent.
Refer to the earlier program.
If you look at the form you will see a Green shield and Red shield picture, and two white pictureboxes.
The Green shield and Red shield pictures are transparent Gifs that were loaded from the IDE.
They were loaded into pictureboxes with black backgrounds.
They are copied during initialization into pictureboxes with white backgrounds.

If you run the program, then pause it by hitting the pause symbol (II) or pressing Ctrl-Break,you can enter this code in the immediate window to see the pictureboxes.

for q = 0 to 3: picture3(q).Visible = True:next

You will see the black background showing through on the left (even index) pictures, and the white background showing through on the right (odd index) pictures.

Do you have AutoResize set True (although that shouldn't matter as long as both the white background and black background pictureboxes are the same size).

You should pause your program, and examine the pictureboxes (or not hide the pictureboxes when first developing), to verify that you have pictureboxes with White and Black backgrounds that are showing through the transparent area of the gif.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #12  
Old 07-18-2005, 07:20 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

It seems to be fine with the fact the image is transparent, but it just shows through the greyness
Attached Images
File Type: bmp ducks.bmp (188.3 KB, 7 views)
__________________
Bool isStupid = True
Reply With Quote
  #13  
Old 07-18-2005, 07:22 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

How about posting the code.
I'll try to capture your images from the bmp you posted and try a test, but it should work if the correct raster Op is used on the correct bitmap.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #14  
Old 07-18-2005, 07:30 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Quote:
Originally Posted by passel
How about posting the code.
I'll try to capture your images from the bmp you posted and try a test, but it should work if the correct raster Op is used on the correct bitmap.
I think you have a PM
__________________
Bool isStupid = True
Reply With Quote
  #15  
Old 07-18-2005, 07:40 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Yes, I'm looking at it.
This is the test code I put together.
You code looks alright, but I'll have to give it a run to be sure.
Attached Files
File Type: zip duck.zip (2.4 KB, 12 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #16  
Old 07-18-2005, 07:46 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Ok, I looked at your code a little closer.
You're bitblting your pictures into another picturebox, and moving that picturebox.
I assume the gray area around your duck is the backcolor of that picturebox.
You shouldn't be bitblting into a picturebox and then moving the picturebox.
That picturebox is still not going to be transparent, event though the picture you drew into it is (as evidenced by the fact that the background of that picturebox is showing through).
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #17  
Old 07-18-2005, 07:54 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Quote:
Originally Posted by passel
Ok, I looked at your code a little closer.
You're bitblting your pictures into another picturebox, and moving that picturebox.
I assume the gray area around your duck is the backcolor of that picturebox.
Yeah - the greyness is the backcolour of the picturebox.

Quote:
You shouldn't be bitblting into a picturebox and then moving the picturebox.
That picturebox is still not going to be transparent, event though the picture you drew into it is (as evidenced by the fact that the background of that picturebox is showing through).
So what should I be doing to get the ducks to generate and then fall from random places on the screen? Currently, I can do this fine with an image or picturebox control. I just need to stop either the flickering or the nasty grey stuff.

Where do you propose I bitBlt to? The form?
__________________
Bool isStupid = True
Reply With Quote
  #18  
Old 07-18-2005, 07:55 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Either on the form, or within a "gaming area", like a large picturebox on the form.
Look at the code I attached above. It moves the duck diagonally across the form.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #19  
Old 07-18-2005, 08:00 PM
passel's Avatar
passelFlickering Images passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Or try this modification to your code.
Set AutoRedraw to True for your form.

Code:
Private Sub Timer1_Timer() If (Rnd * 3) < 1 Then Picture1(0).Picture = Picture3.Picture Picture1(1).Picture = Picture3.Picture Else Picture1(0).Picture = Picture3.Picture Picture1(1).Picture = Picture3.Picture End If Cls BitBlt hDC, PosX, PosY, 45, 45, Picture1(0).hDC, 0, 0, vbSrcPaint 'Paint the blackbackground BitBlt hDC, PosX, PosY, 45, 45, Picture1(1).hDC, 0, 0, vbSrcAnd 'And the whitebackground PosY = (PosY + 10) Mod ScaleHeight Me.Refresh End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #20  
Old 07-18-2005, 08:05 PM
Norm Norm is offline
Newcomer
 
Join Date: Jul 2005
Location: Leicester, England
Posts: 17
Default

Quote:
Originally Posted by passel
Either on the form, or within a "gaming area", like a large picturebox on the form.
Look at the code I attached above. It moves the duck diagonally across the form.
Ok - that's cool with me. One problem though is that I can't see a name for this "item". How could I make a
Code:
Private Sub Picture2_Click() End Sub
equivalent for the flying duck?
__________________
Bool isStupid = True
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Flickering Images
Flickering Images
Flickering Images Flickering Images
Flickering Images
Flickering Images
Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images Flickering Images
Flickering Images
Flickering Images
 
Flickering Images
Flickering Images
 
-->