I have a form with black background, with 9 picture boxes.
When the program starts, I want to show 9 images using these picture boxes.
However, the picture boxes take time to load the picture. It is quite ugly that the picture boxes show up first while waiting.
Is there a way I can move from blank black screen to straightaway 9 images, without the visible loading in between?
Thanks.
How are you loading your Form (I guess you are talking about Windows.Forms here)?
You can just create a new Window class and load your pictures and then after all is done call the Show method.
MyForm form = new MyForm ();
form.DoLoadImages ();
form.Show ();
Or you can just set the WaitOnLoad property of the PictureBox to true.
private void startButton_Click(object sender, EventArgs e)
{
// Ensure WaitOnLoad is false.
pictureBox1.WaitOnLoad = false;
// Load the image asynchronously.
pictureBox1.LoadAsync(#"http://localhost/print.gif");
}
Courtesy of MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.waitonload(v=VS.100).aspx1
Related
My project consists of a video player and a image viewer, both fullscreen in a panel with only one visible at a time. When the video pauses I capture the frame, display it in the image viewer and swap which control is visible. The problem is, when the image viewer is shown you see the previous image for a brief second before the new image is painted.
Does anyone have any suggestions on how I can prevent this? Ideally I want it to be seemless when the controls swap.
I've already set the image viewer to be double buffered.
Edit:
Code, doesn't really show much here.
private void ShowImageView()
{
this.axWindowsMediaPlayer.Visible = false;
this.imageViewer.Visible = true;
}
private void ShowVideoView()
{
this.axWindowsMediaPlayer.Visible = true;
this.imageViewer.Visible = false;
}
I've managed to solve it, the image viewer had a Image Changed event that I hadn't spotted (I'd tried using the Image Loaded event). Subscribing to the image changed event and only showing the control then, seems to give me the transistion I was looking for.
I am making use of the AForge class library.
From this library I am using VideoSourcePlayer to take photos with the webcam.
My purpose is to create a function that allows the user to photograph images to establish them as company logo.
Not only can you choose images from the computer, but you can also capture images from the outside through the camera, since you may only want to transfer a logo of a physical support (paper) to the program.
As commented earlier in SO, (how to pause a video file played using videosourceplayer), VideoSourcePlayer does not have a Pause method or any function that allows to freeze the image.
Yes, it is true that it has the GetCurrentFrame() method, but that only gets a Bitmap from the current frame that must be passed to a PictureBox.
But I want that when the user clicks the button Capture the image of the VideoSourcePlayer simulate being frozen, and when the user presses the Delete button because he did not like the photo, then the image stops being frozen and recovers its movement.
Logic is like pausing or playing a video.
Well, there's no method for it, so I decided to look for another way to get this, and ...
If a picture is taken, use a PictureBox that contains the last frame and that is displayed on the VideoSourcePlayer, but if it is deleted, then the PictureBox is removed and the VideoSourcePlayer is returned with video.
private readonly Bitmap EmptyBitmap;
private void CaptureBtn_Click(object sender, EventArgs e)
{
Bitmap bitmap = this.VideoSource.GetCurrentVideoFrame();
ShowTakedFrame(bitmap, false);
}
private void ShowTakedFrame(Bitmap Frame, bool remove)
{
var picture = new System.Windows.Forms.PictureBox();
picture.Size = this.VideoSource.Size;
picture.Location = this.VideoSource.Location;
if (!remove)
{
this.VideoSource.Stop();
picture.Image = Frame;
this.Controls.Remove(VideoSource);
this.Controls.Add(picture);
}
else
{
this.Controls.Remove(picture);
this.Controls.Add(VideoSource);
this.VideoSource.VideoSource = this.CaptureDevice;
this.VideoSource.Start();
}
}
private void DeleteBtn_Click(object sender, EventArgs e)
{
ShowTakedFrame(EmptyBitmap, true);
}
My problem is that when capturing the photo, the image is a few seconds after the moment when you press the Capture button and when you delete the captured image, using the Delete button, the video of the VideoSourcePlayer is frozen.
Can someone help me with this?
The problem is that when you remove the PictureBox and add the VideoSourcePlayer, it creates a new object, that is, one that does not have the configuration properties of the previous one. My recommendation is that you create the capture in a different form.
i am currently learning on webcam based qr code decoder i have taken an example from https://zxingnet.svn.codeplex.com/svn/trunk/Clients/AForgeDemo/ . i have manage to get it working however i have a problem which baffle me. it is regarding to the picture box in my GUI.
the image above is before i press the start/ continue button. the image after is as below
is there any setting in the picture box property which could prevent the picturebox from expanding or do i need to type a source code to. it would be great if anyone could highlight what i need to do to prevent the expending of the picture box. thank you
Set the MaximumSize property of the picture box to however big you want it to be. You can also set MinimumSize while you're at it.
Hey Try This Code on click of Start Button
private void Button1_Click(System.Object sender, System.EventArgs e)
{
// Set the SizeMode property to the StretchImage value. This
// will enlarge the image as needed to fit into
// the PictureBox.
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
Hope it will helps you
Seems like you have to set PictureBox.SizeMode to everithing else than AutoSize.
I've some huge images (7000*5000) to load simultaneously in my program, which I'm displaying in picturebox one by one. These images take some time to load in the PictureBox. At first I'm loading all the images in an Image array as Bitmap, then I'm just showing the first image in picturebox picturebox.Image = imageArray[0]. So I want to show wait cursor until first image is shown in Picturebox. Is there any way to know when the first image is shown on Picturebox?
You can use the PictureBox events : LoadProgressChanged to show the loading progress and LoadCompleted to do something when it is finished.
private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
{
// animate a progressbar...
}
private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
// done !
}
To make this work, you have to keep the .WaitOnLoad value property to False, and you have to use one of the LoadAsync method.
hi
How to display a wait gif over the screen for 5 second
i want to show a loading image(Gif) over a picturebox. eg when i click on the picturebox , before load another image into this picturebox my loading image(animation image(gif)) showing on the screen for 3 second and this gif image unvisible then another image load into picturebox.
on the other hand How to display a wait gif until image is fully loaded in c#.net 3.5
please help me
thanks
You could use the PictureBox.LoadAsync(string url). The PictureBox will then raise
LoadProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
and
LoadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
events.