Resolved I am trying to make a image slide show with lime interval option

jnkukka

Member
Joined
Mar 26, 2021
Messages
5
Programming Experience
Beginner
I am trying to make a image slide show with lime interval option in my graphics layout. But image slide show work in like a image sequence. can you help me .i am using medialooks mplatform SDK.
thi-is-code-jpg.1477
 

Attachments

  • thi is code.jpg
    thi is code.jpg
    231.1 KB · Views: 157
Please do not post your code as a screenshot. Post the code in code tags.

From what little I can read from your screenshot, it looks like you are iterating over all the images on the button click event instead of incrementing one image at a time each time the timer tick event fires.
 
Please do not post your code as a screenshot. Post the code in code tags.

From what little I can read from your screenshot, it looks like you are iterating over all the images on the button click event instead of incrementing one image at a time each time the timer tick event fires.
I am update my code
C#:
// Sets up an image object to be displayed.
            if (MyImage != null)
            {
                MyImage.Dispose();
            }
            MyImage = new Bitmap(images[imageIX]);

            // Stretches the image to fit the pictureBox.
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = (Image)MyImage;
            imageIX++;
            if (imageIX > 10)
                timer1.Stop();
 

Attachments

  • update timer.jpg
    update timer.jpg
    212 KB · Views: 16
Good. So does the code now work correctly? If not, what behavior are you seeing? What have you done to try to figure out why it is not working correctly?
 
What have you done to try to figure out why it is not working correctly?
 
From what I can try to read from that newest screenshot, it looks like you have a null exception error due to images array being null.

If you are getting an exception, there is no need for a screenshot. You can simply click on the "Copy details" link on the exception and paste in the information into code tags here.
 
From what I can try to read from that newest screenshot, it looks like you have a null exception error due to images array being null.

If you are getting an exception, there is no need for a screenshot. You can simply click on the "Copy details" link on the exception and paste in the information into code tags here.
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=CGEditor_WinForms
StackTrace:
at CGEditor_WinForms.MainWindow.timer1_Tick(Object sender, EventArgs e) in E:\test work\CGEditor_WinForms\MainWindow.cs:line 1000
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at PlaylistSample.Form1.CgEditorButton_Click(Object sender, EventArgs e) in E:\test work\Playlist Sample\Form1.cs:line 295
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at PlaylistSample.Program.Main() in E:\test work\Playlist Sample\Program.cs:line 17
 
The error message is telling you that you're getting a NullReferenceException and where it is thrown. Have you searched the web to find out what exactly that exception means? Assuming you do know what it means, have you debugged the code and examined the references on that line to see which one(s) is null? There aren't many options.

Beginners often think "I don't know what to do so I'm going to do nothing". It is very rare that there really is nothing you can do. You have keywords all around you - most notably NullReferenceException in this case - so you ALWAYS have the option of searching the web using those keywords to try to get more useful information. If you knew what a NullReferenceException was then you'd have a much better chance of diagnosing it, so you should be trying to find out what it is.

That said, @Skydiver has pretty much told you what the problem is. You appear to be trying to get an element from an array that doesn't exist. Have you checked whether images is null or not when the exception is thrown? If not, why not? If so, is it null? If it is then where exactly do you think it should been assigned a value? If there is no such line of code then the issue is obvious. If there is such a line then you need to debug your code. Place a breakpoint on that line to make sure that it's hit and, if it is, place a watch on the variable and step through the code to see when it get reset.
 
The error message is telling you that you're getting a NullReferenceException and where it is thrown. Have you searched the web to find out what exactly that exception means? Assuming you do know what it means, have you debugged the code and examined the references on that line to see which one(s) is null? There aren't many options.

Beginners often think "I don't know what to do so I'm going to do nothing". It is very rare that there really is nothing you can do. You have keywords all around you - most notably NullReferenceException in this case - so you ALWAYS have the option of searching the web using those keywords to try to get more useful information. If you knew what a NullReferenceException was then you'd have a much better chance of diagnosing it, so you should be trying to find out what it is.

That said, @Skydiver has pretty much told you what the problem is. You appear to be trying to get an element from an array that doesn't exist. Have you checked whether images is null or not when the exception is thrown? If not, why not? If so, is it null? If it is then where exactly do you think it should been assigned a value? If there is no such line of code then the issue is obvious. If there is such a line then you need to debug your code. Place a breakpoint on that line to make sure that it's hit and, if it is, place a watch on the variable and step through the code to see when it get reset.
I am change my code like this:
 private void timer1_Tick(object sender, EventArgs e)
        {
            // Sets up an image object to be displayed.
            if (MyImage != null)
            {
                MyImage.Dispose();
            }
       
            try
            {
                MyImage = new Bitmap(images[imageIX]);
            }
            catch (Exception)
            {
               
            }

            // Stretches the image to fit the pictureBox.
           
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = (Image)MyImage;
            imageIX++;
            if (imageIX > 10)
                timer1.Stop();

        }

Now its working
 
You don't need try-catch there, you can validate instead. If array can be null you can check for that, you can also check if index is valid.
It could also be a good idea to find out why the conditions would not be valid, for example why would the timer run if there isn't an array, or why would the index not be valid?
 
Now its working
Unfortunately you fixed it the wrong way.

Your fix is like taking the fuse out of the engine oil change light because the oil light comes on every few months. The correct thing to do would be to change your oil and reset the light. The incorrect fix is to just ignore the light or take the fuse out for that light.

In the case of your code, since you are just eating the exception, you are now using a disposed image by the time you get to line 21.
 
Back
Top Bottom