Capture am image from webcam and save - asp.net

Hello guys im trying to save a picture taken from my webcam.
im actually using this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class ImageConversions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CreatePhoto();
}
void CreatePhoto()
{
try
{
string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);
FileStream fs = new FileStream("C:\\Webcam.jpg", FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs);
br.Write(photo);
br.Flush();
br.Close();
fs.Close();
}
catch (Exception Ex)
{
}
}
}
The application RUNS, i get to see the image , i click the capture button it gives no error till here BUT BUT BUT ... NO IMAGE IS SAVED EITHER i downloaded the sample from
HERE : http://www.dotnetspider.com/resources/38150-Capture-save-images-from-Web-camera.aspx (check the attachemnt)

Change Path.. I also had same problem..
Your C Drive Has security level high,
Change path to "D:\Webcam.jpg" and it will work

Try this article. It works pretty good. But I couldn't work with a custom message when webcam is not attached. It gives a auto generated error message.
webcamlibrarydotnet

Related

Consuming a live REST services in ASP.NET

Can you point me to a good and working examples of how to Consume Restful services in web ASP.net. Tutorials, walk-through or any useful material. I just join a company that require me to do that and I am new to ASP.net especially the rest service. I have used many materials and yet not clear.
Help me with the A B C of Rest usage in ASP.net pls
Here is a code that works with my Rest Servive.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using System.IO;
using System.Runtime.Serialization.Formatters;
using System.Net;
namespace WebTestRestfullService
{
public partial class _Default : Page
{
public string JS;
public string resp;
protected void Page_Load(object sender, EventArgs e)
{
}
public void Page_Init(object sender, EventArgs e)
{
using (var client = new HttpClient())
{
//client.BaseAddress = new Uri("http://88.208.232.99:0000");//Dont use this.
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("Application/json"));
//This is wrong too
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("Correct/api/"));
string query = "Correct/api/";//You must get the api refernce correct.
// HTTP GET
//HttpResponseMessage response = await client.GetAsync(". ");
string resp = "";
var task = client.GetAsync(query).ContinueWith
((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonstr = response.Content.ReadAsStringAsync();
jsonstr.Wait();
resp = jsonstr.Result;
});
task.Wait();
Response.Write(resp);
// string data = $.parseJSON(lbltest.Text);
// Session["resp"] = resp;
// new code
}
}
}
}
I have been working on a REST client library that works on all .NET based platforms.
https://bitbucket.org/MelbourneDeveloper/restclient-.net
There is a sample REST service there that calls another REST service. The service is written for ASP.NET Core so it should help you.

ASP.NET StreamWriter filename as variable

I have some ASP.net code that I am working with and I am running into a silent failing.
using System;
using System.IO;
using System.Web;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
[WebMethod(EnableSession=false)]
public static string ProcessData()
{
string chartFile = HttpContext.Current.Server.MapPath("~/Example/chartData.json");
//StreamWriter chartData = new StreamWriter(chartFile);
StreamWriter chartData = new StreamWriter("C:\\_Sites\\Example\\chartData.json");
chartData.WriteLine("Test This Out");
chartData.Flush();
chartData.Close(); // Close the instance of StreamWriter.
chartData.Dispose(); // Dispose from memory.
return chartFile;
}
}
The code I have commented out fails silently. I know the path is being correctly placed into chartFile. I think StreamWriter is not super happy about the var possibly due to the : and \ not being escaped in the string.
I cannot provide a direct path due to the nature of the deployment server. Any suggestions on how to get StreamWriter to play nice with the string contained in chartFile?
Thanks in advance.

How to connect an ASP.NET web application to the phone attached to the COM Port?

I am developing a application which can receive SMS messages and after reading it to send replies as SMS.
For this, I am attaching a nokia 7210 Supernova via USB to act as the GSM modem for showing demo.
This is what in my mind. But I don't know how to proceed with this. Can anyone give me good guidance??
I found a way using AT commands.
I just tested using this code snippet:
I tried to dial a number. But nothing happened in the phone.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String mobileNumber = "121312";
SerialPort sp1 = new SerialPort("COM10", 9600);
sp1.Open();
sp1.WriteLine("ATD" + mobileNumber + ";");
sp1.Close();
}
}
}
i dont think this is a good idea. there are tons of webservices which are cheaper and faster.
the other option if you want 100% control is to connect to a sms gateway of a provider via modem / isdn.

Extract text and image from a pdf in a selected area or coordinates

I have a specific requirement of extracting text and images from a specific area in a pdf file.The area might be a selected or highlighted or from a given set of coordinates.
When i went through, all the approaches are to extract images and text entirely from the PDF on not in a specified location.
I tried with iTextSharp,Syncfussion,Apose but couldn figure out a better approach for this.
If somebody could help me out in this it would be greatfull. Can you share your ideas and suggestion on how to implement this in .net.
Regards,
Arun.M
this code extract images from pdf
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Drawing.Imaging;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bytescout.PDFExtractor;
namespace ExtractAllImages
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// This test file will be copied to the project directory on the pre-build event (see the project properties).
String inputFile = Server.MapPath("sample1.pdf");
// Create Bytescout.PDFExtractor.ImageExtractor instance
ImageExtractor extractor = new ImageExtractor();
extractor.RegistrationName = "demo";
extractor.RegistrationKey = "demo";
// Load sample PDF document
extractor.LoadDocumentFromFile("sample1.pdf");
Response.Clear();
int i = 0;
// Initialize image enumeration
if (extractor.GetFirstImage())
{
do
{
if (i == 0) // Write the fist image to the Response stream
{
string imageFileName = "image" + i + ".png";
Response.Write("<b>" + imageFileName + "</b>");
Response.ContentType = "image/png";
Response.AddHeader("Content-Disposition", "inline;filename=" + imageFileName);
// Write the image bytes into the Response output stream
Response.BinaryWrite(extractor.GetCurrentImageAsArrayOfBytes());
}
i++;
} while (extractor.GetNextImage()); // Advance image enumeration
}
Response.End();
}
}
}

run windows service from asp.net web page

i have a web page written in vb, i need to start a windows service that will be installed in the server.
You first need to add a reference to the System.ServiceProcess assembly. The following code gives you roughly what you want to do (I am using a Label control called messageLabel in the following):
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class StartService : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string serviceName = "Remote Registry";
try
{
StartServiceByName(serviceName);
}
catch (Exception ex)
{
messageLabel.Text = ex.ToString().Replace("\r\n", "<BR>");
return;
}
messageLabel.Text = String.Format("Service {0} started.", serviceName);
}
private void StartServiceByName(string serviceName)
{
ServiceController serviceController = new ServiceController(serviceName);
serviceController.Start();
}
}
However, there is a further thing - you need to have the web server have permission to change this service - which is something that normally can be only done with Administration rights.
haven't tested.
pleas try if works or not. you could add following code in btn click event.
dim controller as new ServiceController
controller.MachineName = "." //try the machine name
controller.ServiceName = "service name"
dim status as string = controller.Status.ToString
' Stop the service
controller.Stop()
' Start the service
controller.Start()
Depending on the permissions that the web site account has, you can start / stop services.
In addition to what others have answered, you can shell out NET START with the appropriate parameters.
You can also do this for remote computers as long as the permissions are granted (I think it has to be a domain account for this).

Resources