Sunday 15 May 2011

c# - How do I create an array of type ImageSource? -


I'm trying to create an array of images to set on my image control. There is a loop which will run through the pictures and display each for each other until it is closed on a random picture.

My approach: I have stored the image path in a string, which I then put in an array. Inside my loop, I am creating a new image source and defining it by array item which is to change it. I believe my program will not work that ImageSource can not drag the image from the file and the image controller sleeps to display the picture for a second before setting it sufficiently.

Here is my code (values ​​are the right path strings and I tried countless Thread.Sleep () variable)

This code runs but it only gets faster instead of all of them Displays the last picture of the flipping through the block, then stopping the last photo

By creating an image type array, can "pictures on hand" be displayed faster? Can WPF Image Controller Support the Need to Receive and Setup Images? Before executing my sleep thread very fast, the image is set up and shown? Private Zero ButtonClick (Object Sender, RoutedEventArgs E) {String [] picArray = New String [] {Kristen, Justin, Brandon, Sarh, Mile, Nina}; Int i = 0; X = rnd Next (0,5); While (i & lt; rnd.Next (10,50)) {ImageSource _currentPic = new bitmap image (new URI (picare [x]); CImage.Source = _currentPic; if (x == 5) x = 0; and X ++; Thread.Sleep (100); i ++;}}

To pause the loop, it stops at the "random" point in the array, whose photo method ends

Thanks before the time.

If this were a normal Windows form , Then you could use it

  before refreshing it. Refresh the screen (current image Displaying)   

However, because it is WPF, you must close that loop in a different thread (like BackgroundWorker ) Another option would be to set the timer and call the contents of the loop every time a timer is executed.

However, you must take that argument into the new thread, WPF .

No comments:

Post a Comment