Results 1 to 14 of 14

Thread: [RESOLVED] Error in calling a class

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Resolved [RESOLVED] Error in calling a class

    Hi, i have a class, with 2 functions in it. I am calling them like normal, but it seems to error.

    My class:

    c# Code:
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Drawing;
    6.  
    7. namespace WebBrowser
    8. {
    9.     class Mypicssave
    10.     {
    11.         public static void Mypictures(Bitmap thumbnail)
    12.         {
    13.             String SaveName = DateTime.Now.ToShortDateString().Replace("/", "-") + ".png";
    14.             thumbnail.Save(Environment.SpecialFolder.MyPictures + @"\" + SaveName, System.Drawing.Imaging.ImageFormat.Png);
    15.         }
    16.         public static void Specicifed(Bitmap thumbnail)
    17.         {
    18.             String SaveName = DateTime.Now.ToShortDateString().Replace("/", "-") + ".png";
    19.             thumbnail.Save(Properties.Settings.Default.specifiedfolder + @"\" + SaveName, System.Drawing.Imaging.ImageFormat.Png);
    20.         }
    21.  
    22.     }
    23.  
    24. }


    And my error:

    http://true.zxq.net/error.PNG

    Any chance someone could help me?

    The full source with the error in calling the class in here:
    http://pastebin.com/f5826d534


    Thanks in advance

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Hey,

    The picture with your error message is not working. Can you correct this?

    Gary

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Re: Error in calling a class

    Okay, well its working for me, try again, but i could just upload so:
    Attached Images Attached Images  

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Re: Error in calling a class

    Okay, well its working for me, try again, but i could just upload so:

    Attached Images Attached Images  

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Hey,

    Ok, that's better.

    So you have defined a method as:

    Code:
    public static void Mypictures(Bitmap thumbnail)
    It is expecting a parameter of type Bitmap when it is called, but you are not giving it one. You would need to call it like:

    Code:
    Mypicsave.MyPictures(myBitmap);
    Where myBitmap is an instance of a Bitmap class that you want to work with.

    Gary

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Re: Error in calling a class

    Okay, so if i put mybitmap it should work? Or would i have to put thumbnail or something?

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Hey,

    mybitmap was just an example variable name, to indicate how it should be called. I was assuming that elsewhere in your code you already have a variable of type Bitmap that you are using. Is this not the case?

    Gary

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Re: Error in calling a class

    Well i have the thumbnail generate image, which i want to be saved and when i replace myBitmap with thumbnail it errors too, so im not sure...could you look through the whole source link and see what is what..Please?

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Hey,

    What is the error that you are getting now?

    Gary

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Oh, I see what it is...

    Code:
    private void screenshotToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (Properties.Settings.Default.prompt == true)
                {
                    Bitmap thumbnail = GenerateScreenshot(webBrowser1.Url.ToString());
                    SaveFileDialog saveDialog = new SaveFileDialog();
                    saveDialog.Filter = "JPeg Image|*.jpg";
                    saveDialog.Title = "Save Image as";
                    saveDialog.ShowDialog();
                    if (saveDialog.FileName != string.Empty)
                        thumbnail.Save(saveDialog.FileName, ImageFormat.Jpeg);
     
                    thumbnail.Dispose();
                }
                else if (Properties.Settings.Default.Mypics == true)
                    {
                        Mypicssave.Mypictures();
                    }
     
                else if (Properties.Settings.Default.Specified == true)
                    {
                        Mypicssave.Specicifed();
                    }
                        }
    thumbnail is created within the first if statement, as a result, it does not exist when/if you go into the else if statements. You are likely getting a compile error saying that thumbnail is not declared anywhere. Try the following:

    Code:
    private void screenshotToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Bitmap thumbnail = GenerateScreenshot(webBrowser1.Url.ToString());
    
                if (Properties.Settings.Default.prompt == true)
                {
                    SaveFileDialog saveDialog = new SaveFileDialog();
                    saveDialog.Filter = "JPeg Image|*.jpg";
                    saveDialog.Title = "Save Image as";
                    saveDialog.ShowDialog();
                    if (saveDialog.FileName != string.Empty)
                        thumbnail.Save(saveDialog.FileName, ImageFormat.Jpeg);
     
                    thumbnail.Dispose();
                }
                else if (Properties.Settings.Default.Mypics == true)
                    {
                        Mypicssave.Mypictures(thumbnail);
                    }
     
                else if (Properties.Settings.Default.Specified == true)
                    {
                        Mypicssave.Specicifed(thumbnail);
                    }
                        }
    Gary

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Re: Error in calling a class

    Wow, works perfectly! Thanks alot Gary! You rule

    Do you have msn? Everyones at school :P haha xD

    Thanks again!

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Hey,

    Not a problem at all!

    I have msn yes, but I don't answer coding questions via it

    Gary

    P.S. Remember to mark your thread resolved.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    19

    Re: Error in calling a class

    haha okay, just to talk And wil do...im kinda new as you see, VERY low post count, so how do you mark as resolved?

  14. #14
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Error in calling a class

    Okay dokay.

    If you follow the link in my signature, you will see how to mark your thread resolved.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width