[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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace WebBrowser
{
class Mypicssave
{
public static void Mypictures(Bitmap thumbnail)
{
String SaveName = DateTime.Now.ToShortDateString().Replace("/", "-") + ".png";
thumbnail.Save(Environment.SpecialFolder.MyPictures + @"\" + SaveName, System.Drawing.Imaging.ImageFormat.Png);
}
public static void Specicifed(Bitmap thumbnail)
{
String SaveName = DateTime.Now.ToShortDateString().Replace("/", "-") + ".png";
thumbnail.Save(Properties.Settings.Default.specifiedfolder + @"\" + SaveName, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
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 ;)
Re: Error in calling a class
Hey,
The picture with your error message is not working. Can you correct this?
Gary
1 Attachment(s)
Re: Error in calling a class
Okay, well its working for me, try again, but i could just upload so:
1 Attachment(s)
Re: Error in calling a class
Okay, well its working for me, try again, but i could just upload so:
http://true.zxq.net/error.PNG
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
Re: Error in calling a class
Okay, so if i put mybitmap it should work? Or would i have to put thumbnail or something?
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
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?
Re: Error in calling a class
Hey,
What is the error that you are getting now?
Gary
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
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!
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.
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?
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