Jan 7th, 2010, 05:07 AM
#1
Thread Starter
Junior Member
[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
Jan 7th, 2010, 05:30 AM
#2
Re: Error in calling a class
Hey,
The picture with your error message is not working. Can you correct this?
Gary
Jan 7th, 2010, 05:43 AM
#3
Thread Starter
Junior Member
Re: Error in calling a class
Okay, well its working for me, try again, but i could just upload so:
Attached Images
Jan 7th, 2010, 05:45 AM
#4
Thread Starter
Junior Member
Jan 7th, 2010, 05:46 AM
#5
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
Jan 7th, 2010, 05:48 AM
#6
Thread Starter
Junior Member
Re: Error in calling a class
Okay, so if i put mybitmap it should work? Or would i have to put thumbnail or something?
Jan 7th, 2010, 05:52 AM
#7
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
Jan 7th, 2010, 05:59 AM
#8
Thread Starter
Junior Member
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?
Jan 7th, 2010, 06:01 AM
#9
Re: Error in calling a class
Hey,
What is the error that you are getting now?
Gary
Jan 7th, 2010, 06:04 AM
#10
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
Jan 7th, 2010, 06:09 AM
#11
Thread Starter
Junior Member
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!
Jan 7th, 2010, 06:10 AM
#12
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.
Jan 7th, 2010, 06:12 AM
#13
Thread Starter
Junior Member
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?
Jan 7th, 2010, 06:14 AM
#14
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
Forum Rules
Click Here to Expand Forum to Full Width