473,657 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a video background using frames and timer?

sword117
35 New Member
Im trying to create a video background using frames from a video, and using a timer to run the frames 30FPS , can someone help me out? its for a school project.

im here so far, i can make this work with a trackbar, but using a timer to automatically refresh the background 30FPS would be a lot more cool =).

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using System.Diagnostics;
  12. using System.Threading;
  13.  
  14. namespace MyClock
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.  
  22.         }
  23.  
  24.  
  25.  
  26.         private void Form1_Load(object sender, EventArgs e)
  27.         {
  28.             Text = "My Clock";
  29.         }
  30.  
  31.         private void timer1_Tick(object sender, EventArgs e)
  32.         {
  33.             //timer1.Interval = 1000;
  34.             //FPS set up
  35.             double FPS = 30.0;
  36.  
  37.             timer1.Interval = Convert.ToInt32(FPS);
  38.  
  39.              Image[] images = new Image[2003];
  40.              for (int i = 1; i < 10; i++)
  41.              {
  42.                  images[i] = Image.FromFile(@"C:\Users\Sword Master\Desktop\New folder (6)\PS3 Background Waves Attempt HD (08-07-2010 23-45-07)\PS3 Background Waves Attempt HD 000" + i + ".jpg");
  43.                  this.BackgroundImage = images[i];
  44.              }
  45.            //test if the timer works
  46.             label2.Text = DateTime.Now.ToLongTimeString();
  47.         }
  48.  
  49.     }
  50. }
  51.  
  52.  
Jul 15 '10 #1
33 7223
GaryTexmo
1,501 Recognized Expert Top Contributor
We can't really do your homework for you, but we can help you out.

What question specifically do you have about a timer?

Here's something to try... on your form, drop down a timer. Set the interval to say, 1000 (milliseconds, 1 second). Attach a handler to the tick event and put something visible in there, maybe a Console.WriteLi ne("Ticked!");

Hopefully that's enough hint to get you started :)
Jul 15 '10 #2
sword117
35 New Member
@GaryTexmo
=) okay i already done that, but my question here is more like how do i put the timer to search the image[i] and show the images on a speed of 30 FPS, but my main problem is how to say that on the timer1_tick(lik e the interval), i really dont know where to start, i tried everything that i found on google and still had no results,please give me a light =)
Jul 15 '10 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
Two things...

1) If you want to run through an image in an array, you'd going to need some kind of counter, right? A class member variable might be appropriate here... What I mean by this is, what is images[i]? You're accessing it via a for loop, right? Well, you kind of want to replace your for loop with the timer itself...

2) What does FPS actually mean? Frames per second. If you had 30 frames per second, how many seconds would it be per frame? Where on the timer can you enter an amount relating to seconds?

(Hopefully that nudges ya in the right direction. You've clearly stated what you want to do, you've just gotta play around with a timer to learn how you can use it to your advantage.)
Jul 15 '10 #4
sword117
35 New Member
@GaryTexmo
im using 2003 images, and i want to show them, but if i dont get to control the speed that they are showed i dont see the images, thats why i created a for, but im only doing it to 10 just like a test drive.

I say 30FPS because it shows 30 frames a second, i see in games that the img flows right, and im trying too do that, it actualy doesnt need to be 30FPS, just the speed need to flow nomal.

but thanks again =)
Jul 16 '10 #5
sword117
35 New Member
@sword117
Hello again =) i managed to what i want with a scrool bar, but i cannot control the trackbar value... so i thinked of the timer.

here is the code to create a flow of images.

Expand|Select|Wrap|Line Numbers
  1.   private void trackBar1_Scroll_1(object sender, EventArgs e)
  2.         {
  3.              Image[] images = new Image[2003];
  4.                 for (int i = 1; i < 10; i++)
  5.                 {
  6.                     images[i] = Image.FromFile(@"C:\Users\Sword Master\Desktop\New folder (6)\PS3 Background Waves Attempt HD (08-07-2010 23-45-07)\PS3 Background Waves Attempt HD 000" + i + ".jpg");
  7.  
  8.                     if (trackBar1.Value == i)
  9.                     {
  10.                         this.BackgroundImage = images[i];
  11.                     }
  12.  
  13.                 }
  14.                 label1.Text = trackBar1.Value.ToString();
  15.  
  16.         }
Jul 16 '10 #6
GaryTexmo
1,501 Recognized Expert Top Contributor
im using 2003 images, and i want to show them, but if i dont get to control the speed that they are showed i dont see the images, thats why i created a for, but im only doing it to 10 just like a test drive.

I say 30FPS because it shows 30 frames a second, i see in games that the img flows right, and im trying too do that, it actualy doesnt need to be 30FPS, just the speed need to flow nomal.

but thanks again =)
Like I said, think about what frames per second actually means. That's the number of frames shown in a second. This value is easily converted to how many seconds we show each frame...

30 frames per seconds --> 1/30 seconds per frame, this is 33.33 milliseconds per frame. There's a place on your timer exactly for this.

Now what does your timer need to do? It needs to advance your frame counter, then update the drawing. In your case, the background image.

With the code you've posted, you'll never see more than 10 images cycle and only when the user scrolls the track bar. Keep on with the timer, you'll get there :D Just think about it and before you know it, you'll have one of those "oooooooh" moments.

By the way, it just so happens that about a year ago I did almost exactly this with a little animation from Mega Man X. You're welcome to see the code, but I'm going to make you figure this out first ;) Trust me, you'll be happier for it.
Jul 16 '10 #7
sword117
35 New Member
@GaryTexmo
Thank you very much! =) i made it lol
but now i have another problem, the form becomes unusable when i click it, or move it, button´s dont work...

i saw in the toolbox the background worker, if i put this code there will i be able to click on the form?

thanks a lot =)

Expand|Select|Wrap|Line Numbers
  1. private void timer1_Tick(object sender, EventArgs e)
  2.         {
  3.  
  4.             Image[] images = new Image[2003];
  5.             timer1.Interval = 1000 / 30;
  6.  
  7.             for (int i = 32; i <= 2001; i++)
  8.             {
  9.                 if (i <= 2001)
  10.                 {
  11.                     this.Refresh();
  12.                     images[i] = Image.FromFile(@"C:\Users\Sword Master\Desktop\New folder (6)\PS3 Background Waves Attempt HD (08-07-2010 23-45-07)\1 (" + i + ").jpg");
  13.                     this.BackgroundImage = images[i];
  14.                     label2.Text = i.ToString();
  15.  
  16.  
  17.                 }
  18.                 else
  19.                 {
  20.                     return;
  21.                 }
  22.  
  23.             }
  24.  
  25.         }
Jul 16 '10 #8
GaryTexmo
1,501 Recognized Expert Top Contributor
You're close, but not quite there :)

Take a look at what you're doing in your timer tick method. Every 33.33 milliseconds you're setting the timer tick to 33.33 milliseconds, then you're looping through every image in the list.

You do not need to do this. Your timer's tick method is what changes the drawn image. Read: You do not need the for loop at all.

Also, preload all your images into the image array in the constructor or form load event. Putting it in the timer tick event makes things very slow as every 33 milliseconds you're loading a file from the hard drive.

Let me try to put this another way. Your tick event just puts an image in the background. The tick happens whenever the timer's interval expires. The interval controls the framerate of the image drawing.
Jul 16 '10 #9
sword117
35 New Member
@GaryTexmo
i think i didnt understand you well xD

is it close to this? lol

Expand|Select|Wrap|Line Numbers
  1.         private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             Text = "My Clock";
  4.             MyClock();
  5.  
  6.         }
  7.  
  8.         public void MyClock()
  9.         {
  10.             Image[] images = new Image[2003];
  11.             for (int i = 32; i <= 2001; i++)
  12.             {
  13.                 images[1] = Image.FromFile(@"Images\1 (" + i + ").jpg");
  14.                 this.BackgroundImage = images[i];
  15.                 label2.Text = i.ToString();
  16.  
  17.             }
  18.         }
  19.  
  20.         private void timer1_Tick(object sender, EventArgs e)
  21.         {
  22.              timer1.Interval = 1000 / 30;
  23.              this.Refresh();
  24.         }
  25.  
Jul 17 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3379
by: dumblede | last post by:
Hello fellows, i would like to center a 800px wide 600px high content area without using frames. I have "come up" with the following solution so far. It works under IE 6.0, Firefox 1 (under Windows and Linux) but not under Konqueror (could not test Safari, but they have the rendering engine in common (see www.kde.org)): <pre>
4
10072
by: Wayne Wengert | last post by:
I'm looking for information or samples of how to display a gradient background color for an ASP.NET web page. I want to be able to set a start and end color (e.g. Light Orange to White) and have the page rendered with that gradient background from left to right. Using google I found several examples but they all appeared to apply only to Windows Forms Wayne
4
2814
by: sirumalla.srinivas | last post by:
Hi, I have link to the various documents which is stored on the server. When ever user click on any link, the respective document should be opened. Here what i need is to have all the links on the left side of the page and when the user clicks the document should be opened on the right side of the application. When googled, some of them told to split the page into two frames, load the document links in left frame and open the document...
0
6742
by: celoftis | last post by:
Using VS2005, VB code behind, BACKGROUND I'm trying to set up a page with a TreeView of links on the left hand side of my page - when clicked I want the links to open in the remaining portion of the page. The best and easiest way I've found todo this is with using frames (any suggestions on other ways todo this I'd love to hear about it). PROBLEM
5
3022
by: Peted | last post by:
i have an mdi application with two child forms Childform A and childform B in a nutshell Childform B has a timer with a routine that polls a ip socket for information every 30sec.
0
1213
by: Muhammad Ammad Saleem | last post by:
Hi, I just want to extract the close captions from Video Clips using C# or the .NET Framework. I want to extract this information so that people can search for Video clips of there desire using the search terms I want to create something like Google Videos. Any help will be appreciated and I need it as soosn as possible. Thanks
1
2295
by: romcab | last post by:
Hi guys, Just want to ask your idea on how to do video streaming using C#. I want to create an application that can play video file. Is there an existing classes that I can reuse? Hope you can help me. thanks,
13
3990
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.aspnet&mid=e9a38d03-83a8-41fc-8950-5ee60d2a18a5. I have a web site under .NET 2.0 that renders videos using the Silverlight media player. When I stream the video file (.wmv) to the browser via a hard-coded link to the file,...
3
2074
by: Stubbulon5 | last post by:
Hi there, Im using a Timer with an interval of 1 min (60000 milliseconds) to start a thread in the Global.cs of my application. Everything works fine until the the thread job takes more than 1 min to complete. When the job takes longer that 1 min, the old (currently running) job never seems to get to completion. Basically I only want to re-run the thread once its complete but using the Timer so I can potentially leave gaps inbetween each...
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.