Click here to Skip to main content
15,907,905 members
Home / Discussions / C#
   

C#

 
GeneralRe: redirecting Pin
Paul Conrad22-Dec-07 9:21
professionalPaul Conrad22-Dec-07 9:21 
Questionhow to deactivate grid cell Pin
amit_8317-Dec-07 23:51
amit_8317-Dec-07 23:51 
QuestionWhat this code is doing Pin
Hum Dum17-Dec-07 23:38
Hum Dum17-Dec-07 23:38 
AnswerRe: What this code is doing Pin
AlwiNus17-Dec-07 23:49
AlwiNus17-Dec-07 23:49 
GeneralRe: What this code is doing Pin
Hum Dum18-Dec-07 1:19
Hum Dum18-Dec-07 1:19 
GeneralRe: What this code is doing Pin
Anthony Mushrow18-Dec-07 1:48
professionalAnthony Mushrow18-Dec-07 1:48 
AnswerRe: What this code is doing Pin
ag4667717-Dec-07 23:50
ag4667717-Dec-07 23:50 
QuestionQuestions about using System.Timers.Timer with clipboard Pin
surfingcode17-Dec-07 22:28
surfingcode17-Dec-07 22:28 
I am writing a program using System.Timers.Timer to trigger the webcam to capture an image and saved in a file.

The image saving function is workable when it works standalone (by clicking a button). However, when I call the image saving function in the OnTimedEvent (event-triggering function) it fails. It will pop up the following error message:

"System.NullReferenceException: Object reference not set to an instance of an object...."

I lately found that the Data could not be retrieved from the clipboard when the clipboard is being used by another process...

Following is the Caputure function of the webCam device... (in Device.cs)
public Image Capture()<br />
        {<br />
        	try{<br />
            if (deviceHandle != 0)<br />
            {<br />
                SendMessage(deviceHandle, WM_CAP_EDIT_COPY, 0, (IntPtr)0);<br />
                IDataObject ido = Clipboard.GetDataObject();<br />
                if (ido.GetDataPresent(DataFormats.Bitmap))<br />
                {<br />
                    return ((Bitmap)ido.GetData(DataFormats.Bitmap));<br />
                }<br />
            }<br />
        	}<br />
			catch (Exception ex)<br />
            {<br />
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
            }<br />
            return null;<br />
<br />
        }


Following is the timer triggering function...

private void OnTimedEvent(object source, ElapsedEventArgs e)<br />
	    {<br />
<br />
            SavingOnePic(Directory.GetCurrentDirectory(), txtSavingName.Text.ToString());<br />
	<br />
	    }



Following is the saving Function, it works when it is called from a button click event. however, does not work in the above OnTimedEvent function.

private void SavingOnePic(string savingPath, string fileName)<br />
		{<br />
			<br />
			try<br />
            {<br />
<br />
				if (!Directory.Exists(@savingPath+@"\capturedImage")) <br />
           		{<br />
                	Directory.CreateDirectory(@savingPath + @"\capturedImage");<br />
                	fileIndex = 0;<br />
				}else{<br />
					string[] fileList = Directory.GetFiles(@savingPath + @"\capturedImage",<br />
					                                   fileName + "*.png");<br />
<br />
					fileIndex = fileList.Length;<br />
				}<br />
				<br />
				Image image = selectedDevice.Capture();<br />
                <br />
                	image.Save(@savingPath + @"\capturedImage\" + fileName + <br />
                	           "_000" + fileIndex.ToString() + ".png", ImageFormat.Png);<br />
                <br />
                fileIndex++;<br />
<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
            }<br />
		}

GeneralRe: And the question is ... Pin
Mircea Puiu17-Dec-07 22:37
Mircea Puiu17-Dec-07 22:37 
GeneralRe: And the question is ... Pin
surfingcode17-Dec-07 22:48
surfingcode17-Dec-07 22:48 
GeneralRe: And the question is ... Pin
AlwiNus17-Dec-07 23:04
AlwiNus17-Dec-07 23:04 
GeneralRe: And the question is ... Pin
Mircea Puiu18-Dec-07 0:43
Mircea Puiu18-Dec-07 0:43 
GeneralRe: And the question is ... Pin
surfingcode18-Dec-07 2:39
surfingcode18-Dec-07 2:39 
GeneralPlease help on regular expression Pin
lordbearsg17-Dec-07 21:11
lordbearsg17-Dec-07 21:11 
GeneralRe: Please help on regular expression Pin
m@u17-Dec-07 21:24
m@u17-Dec-07 21:24 
GeneralRe: Please help on regular expression Pin
lordbearsg17-Dec-07 21:29
lordbearsg17-Dec-07 21:29 
GeneralRe: Please help on regular expression Pin
m@u17-Dec-07 21:46
m@u17-Dec-07 21:46 
GeneralRe: Please help on regular expression Pin
lordbearsg17-Dec-07 22:14
lordbearsg17-Dec-07 22:14 
GeneralRe: Please help on regular expression Pin
m@u17-Dec-07 22:31
m@u17-Dec-07 22:31 
AnswerRe: Please help on regular expression [modified] Pin
Sandilian17-Dec-07 21:58
Sandilian17-Dec-07 21:58 
GeneralRe: Please help on regular expression Pin
leppie18-Dec-07 0:50
leppie18-Dec-07 0:50 
GeneralRe: Please help on regular expression Pin
lordbearsg18-Dec-07 20:45
lordbearsg18-Dec-07 20:45 
GeneralUsing resource strings Pin
ruanr17-Dec-07 20:59
ruanr17-Dec-07 20:59 
GeneralRe: Using resource strings Pin
CKnig17-Dec-07 22:17
CKnig17-Dec-07 22:17 
QuestionApplication settings in winforms programming C# Pin
Zerox MXI17-Dec-07 20:49
Zerox MXI17-Dec-07 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.