473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

[Sprite and Animation with API BitBlt] A way to get this ???

Hallo,

I have to create a simple sprite movement;
in VB6 I used the API BitBlt and all was very good.

Using the NET graphical methods (not API) ,
the result is slow.

Do you have a NET example about BitBlt and the sprite movement ,
because I'm a little in trouble in implementing it
(a simple example could be this ... a Picturebox1 as background
and a small squared Picturebox2 bouncing
inside Picturebox1 from the left to the right) ?

note:
I don't want to use DirectX
Nov 21 '05 #1
7 3966
I don't know about the VB6 aspect of your query but you'll find a
comprehensive example of animation in Windows Forms Tips and Tricks.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"matt" <ma**@inwind.it> wrote in message
news:43**************@aioe.cjb.net...
Hallo,

I have to create a simple sprite movement;
in VB6 I used the API BitBlt and all was very good.

Using the NET graphical methods (not API) ,
the result is slow.

Do you have a NET example about BitBlt and the sprite movement ,
because I'm a little in trouble in implementing it
(a simple example could be this ... a Picturebox1 as background
and a small squared Picturebox2 bouncing
inside Picturebox1 from the left to the right) ?

note:
I don't want to use DirectX

Nov 21 '05 #2
Hi Matt,
because I'm a little in trouble in implementing it


Can you elaborate what trouble do you have?

BTW, BitBlt declaration is:

~
Friend Declare Function BitBlt Lib "gdi32.dll" ( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Integer _
) As Boolean
~

Roman
Nov 21 '05 #3

The animations performed by the Net Framework are slow.
Only the old BitBlt API can assure the needed velocity.

But tthe management of the hdc devices (to pass
as parameter to the BitBlt) are more complex in NET.
This gets me angry (but this is not important);
it is so complex that doesn't allow me to build up
the old simple animation task.
I am stopped.
I don't know about the VB6 aspect of your query but you'll find a
comprehensive example of animation in Windows Forms Tips and Tricks.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"matt" <ma**@inwind.it> wrote in message
news:43**************@aioe.cjb.net...
Hallo,

I have to create a simple sprite movement;
in VB6 I used the API BitBlt and all was very good.

Using the NET graphical methods (not API) ,
the result is slow.

Do you have a NET example about BitBlt and the sprite movement ,
because I'm a little in trouble in implementing it
(a simple example could be this ... a Picturebox1 as background
and a small squared Picturebox2 bouncing
inside Picturebox1 from the left to the right) ?

note:
I don't want to use DirectX



Nov 21 '05 #4

THe problem I have is about
the way to prepare and manage
the hdc devices .

I have two PictureBoxes (destination and source);
in VB6 I only had to write
PictureBox1.hdc and PictureBox2.hdc
and pass them to the BitBlt API.

In NET it seems I can't do this:
I think I have to
create the two devices from both the PictureBoxes,
then I have to create two compatible bmp,
select them as objects,
pass them to te BitBlt API,
set my destination PictureBox equal to the BitBltted image I got,
and finally Delete and Dispose devices.

Actually too complex for me.

Is anyone could help me...




Can you elaborate what trouble do you have?

BTW, BitBlt declaration is:

~
Friend Declare Function BitBlt Lib "gdi32.dll" ( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Integer _
) As Boolean
~

Roman


Nov 21 '05 #5
This works, thanks.
But I have few related questions
(for you or anyone else):

1)
In your opinion, have we also to

ReleaseHdc
or
DeleteDC
or
Dispose

the two hdc we used?

If Yes, how to do that?

2)
If I put only your five rows of code
Dim hDC1 As IntPtr = GetDC(PictureBox1.Handle)
Dim hDC2 As IntPtr = GetDC(PictureBox2.Handle)
BitBlt(hDC2, 0, 0, PictureBox1.Width, PictureBox1.Height, hDC1, 0, 0,
SRCCOPY)
ReleaseDC(PictureBox1.Handle, hDC1)
ReleaseDC(PictureBox2.Handle, hDC2)
(not the whole Protected Overrides Sub OnLoad...)
in the load event, they don't work,

While if I put them (in example) in Command1_Click event,
they work.

Do you know why?

3)
I knew that when declaring an API
we have to transform the Long value in Integer value,
you also transformed the Device parameter into a IntPtr parameter.
Where did you learn it (MSDN guide?) ?
Have you an API Viewer (I have Visual Studio 2005 and I didn't find
any API Viewer and I need it) ?


Nov 21 '05 #6
Hi again,
1)
In your opinion, have we also to

ReleaseHdc
or
DeleteDC
or
Dispose

the two hdc we used?

If Yes, how to do that?
Of course, you have to release all DC's you get. You can see I call
ReleaseDC in the sample.
It's not recommended to call DeleteDC on this kind of DC's, so don't.
You can't Dispose DC since it's unmanaged.

If you want to animate using BitBlt then you obviously shouldn't
create/release DC each time. Create one at the beginning and release it
after animation is done.
2)
If I put only your five rows of code
Dim hDC1 As IntPtr = GetDC(PictureBox1.Handle)
Dim hDC2 As IntPtr = GetDC(PictureBox2.Handle)
BitBlt(hDC2, 0, 0, PictureBox1.Width, PictureBox1.Height, hDC1, 0, 0, SRCCOPY)
ReleaseDC(PictureBox1.Handle, hDC1)
ReleaseDC(PictureBox2.Handle, hDC2)
(not the whole Protected Overrides Sub OnLoad...)
It's OnClick actually 8=]
in the load event, they don't work,

While if I put them (in example) in Command1_Click event,
they work.

Do you know why?
It's probably because Load event occurs before Paint event, so every
painting you got is lost because Picturebox paints itself again with
it's background color.
3)
I knew that when declaring an API
we have to transform the Long value in Integer value,
you also transformed the Device parameter into a IntPtr parameter.
Where did you learn it (MSDN guide?) ?
Have you an API Viewer (I have Visual Studio 2005 and I didn't find
any API Viewer and I need it) ?


Funny, but I can't remember when and where I learned about IntPtr's 8=]
I just recall that at some point I said to myself: "Now, give up these
Int32's & move on to IntPtr, dude!".
I can show you benefits of IntPtr though:
1. It's platform-dependent, so when you move on to 64-bit, you'll
probably have less work to do, since IntPtr's will be 64-bit already.
2. All .NET framework methods that give you (take from you) a handle,
pointer or something like this, they take IntPtr's (Control.Handle,
Marshal.* etc), so you wouldn't have to use .ToInt32 and New IntPtr(...)
stuff.

AFAIK VS'es don't have built-in API viewer. You can try ApiViewer 2004
(http://www.activevb.de/rubriken/apiv...iewereng.html),
however I prefer to make API declarations myself.

Roman
Nov 21 '05 #7
Thanks, very useful.

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DraguVaso | last post by:
Hi, In the override of the Paint-method of a DataGridTextBoxColumn I want to show an image with BitBlt, to see what I can gain there on performance. The problem is: It doesn't show me the image...
5
by: JackS | last post by:
I am trying to use GDI32 bitblt to write a bitmap to a control's window, but all I get is an empty rectangle of some rop-dependent color. In short, I use the following logic in a paint event handler:...
7
by: VB Programmer | last post by:
I am using the BitBlt operation to capture various controls into jpegs. It's almost like a screen capture, but of just the control. (This is a VB.NET application.) Because of BitBlt limitations...
1
by: matt | last post by:
Dragon, there's a reply by me for you (or anyone else) about the post: A way to get this ??? dated 17 Oct 2005 Matt
2
by: Carl | last post by:
I'm new to C#, and I have only limited programming experience. I've been doing the video tutorials at MS's website, and they're very helpful, but I decided to experiment with GDI+ and have gotten...
6
by: Martijn Mulder | last post by:
/* BitBlt.cs C# code using P/Invoke I have good reasons to use P/Invoke to get access to the Win32 API function BitBlt(). But I have trouble understanding the workings of it. Below is a...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main...
0
by: crankeboy | last post by:
Hi Folks, My setup: Visual Studio Express 2008, VC++, .NET, BitBlt Here is a summary of the problem: - I am trying to copy a bitmap of my main form into a picture box. - To do this, I bitblt...
18
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I like to go through the Windows files in a resource editor, just to see what's there. I notice a lot of sprite images that are actually animations. For example, a file 32x256 has 8 tiles each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.