Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Go Back  Xtreme Visual Basic Talk > > > Problem with doors scroll BitBlt functions!


Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2011, 07:27 AM
floring floring is offline
Newcomer
 
Join Date: Mar 2010
Posts: 3
Default Problem with doors scroll BitBlt functions!


Hello guys!
I got stuck with BitBlt Functions. I want to move a bitmap (in a picture box) from left to right (unsolved) and from right to left (resolved) continuous, roll mode. Take a look to the code and tell me please where I'm wrong. Thanks!
Attached Files
File Type: zip Doors Scroll.zip (49.1 KB, 11 views)
Reply With Quote
  #2  
Old 02-07-2011, 04:40 AM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default BitBlt placement issue

Some minor issues:
"Endscroll" as a variable is redundant (but perhaps you have intend to reference it to a larger project so its not hurting anything).
The use of "Me.Refresh" can be an issue.
What you are saying is:
Refresh my whole form and all the controls it contains - which in turn calls Refresh of Picture1 and Refresh of pic1
You really don't need to do all that re-painting.
I tried your code out on an old Celeron computer with an integrated graphics chips and there was some major flickering.
I assume you are using Bitblt to try and avoid flickering.

The better way is to only refresh what you have to by setting the AutoRedraw of the destination picturebox control to True.
Of course you have to add a line to get graphics persistence (and properly use the buffer that AutoRedraw provides).
pic1.Image makes use of the Image Property.

The added line refreshes the picturebox control's Picture from the AutoRedraw backbuffer (copy) stored in the Image property when the picturebox control gets repainted (during bitblt-ing)

The major issue (about the bitblt smearing when "2" is pressed) is not clear thinking when it comes to negative scrolling.
Scrolling left to right is positive so using picture.width for positive placement makes sense, but for right to left placement you must structure the follow-on bitblt call in a negative way.

Just look at the rev1 attachment you'll see what I mean.
Attached Files
File Type: zip Doors Scroll_Rev1.zip (21.5 KB, 19 views)

Last edited by surfR2911; 02-07-2011 at 05:14 AM.
Reply With Quote
  #3  
Old 02-07-2011, 04:35 PM
ZaCkOX's Avatar
ZaCkOX ZaCkOX is offline
Contributor
 
Join Date: May 2006
Location: CA
Posts: 645
Default You need a back buffer...

Animation is done just like a flip book. All the drawings are on seperate pages and you flip the book to see the animation move. What this means is you need a back buffer. Something that already has the next frame and then quickly copy it to the picture box. However don't make more than 2 bitmaps. Just one regular and the back buffer. You won't need all the extra pages when a computer can bitblt to a single page instantly
__________________
ZaCkO ... Who is your attitude?
Reply With Quote
  #4  
Old 02-07-2011, 05:52 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Learning bitblt-ing - moving to animation

You are right ZaCkOX,
but I don't know if floring is ready to go there yet.

floring may still be working to figure out how to do bitblt-ing correctly.
For the future - using an API based timer allows more flexibility than using the Timer control, but you have to learn to walk before you can run.
Reply With Quote
  #5  
Old 02-16-2011, 12:44 PM
passel's Avatar
passelProblem with doors scroll BitBlt functions! passel is offline
Sinecure Expert

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

Late to the game because I'm not here much, but there is really no reason to have two different drawing routines depending on whether you're scrolling left or scrolling right.
Given a positive value of X (between 0 and Picture1.Scalewidth) the first pair of bitblts in the scroll left routine will wrap the drawing properly.
So the code just needs to "move" the value of X (the dividing line) left and right, making sure it is kept positive and in the bounds of the window.
The following code is a version of that, with the addition of any key other than 1 and 2 will stop the timer (and thus the drawing, and without autoredraw or code in the paint event, the image will be erased if something dragged over it).
Code:
Option Explicit Private Declare Function BitBlt Lib "gdi32" _ (ByVal desthdc As Long, ByVal destX As Long, ByVal destY As Long, _ ByVal destWidth As Long, ByVal destHeight As Long, _ ByVal srchdc As Long, ByVal srcX As Long, ByVal srcY As Long, ByVal rOp As Long) As Long Dim MoveRight As Boolean Private Sub stanga_Timer() 'move to left (and right) Dim EndScroll As Long Static X As Long If MoveRight Then X = (X + 3) Mod Picture1.ScaleWidth Else 'move to the left X = (X - 3 + Picture1.ScaleWidth) Mod Picture1.ScaleWidth End If EndScroll = Picture1.ScaleWidth - X BitBlt pic1.hDC, 0, 0, EndScroll, Picture1.Height, Picture1.hDC, X, 0, vbSrcCopy BitBlt pic1.hDC, EndScroll, 0, X, Picture1.Height, Picture1.hDC, 0, 0, vbSrcCopy 'pic1.Refresh 'Only need to refresh if AutoRedraw is set to True on pic1 End Sub Private Sub pic1_KeyPress(KeyAscii As Integer) stanga.Enabled = True If KeyAscii = vbKey1 Then MoveRight = False ElseIf KeyAscii = vbKey2 Then MoveRight = True Else stanga.Enabled = False End If End Sub

The other common way of keeping the X in bounds and positive would be
Code:
If MoveRight Then X = (X + 3) If X > Picture1.ScaleWidth Then X = X - Picture1.ScaleWidth Else 'move to left X = X - 3 If X < 0 Then X = X + Picture1.ScaleWidth End If
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 02-16-2011 at 12:53 PM.
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
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions! Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
 
Problem with doors scroll BitBlt functions!
Problem with doors scroll BitBlt functions!
 
-->