TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bhavesh Vankar
680
1.1k
87.9k
Capture Image using Asp.net Button C#
Jan 2 2021 7:42 AM
When i try to capture image using asp.net button the image not capturing by webcam. and when i capture by html button its capturing image. i want to use asp.net button. what to do in this case...
my code is below...
This is my webmethod to capture image by webcam.
[WebMethod()]
public
static
bool
SaveCapturedImage(
string
data)
{
//string hostName = Dns.GetHostName();
//string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
//myIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
//if (myIP == "" || myIP == null)
//{
// myIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
//}
// string fileName = myIP + DateTime.Now.ToString("dd-MM-yy_hh-mm");
string
fileName = DateTime.Now.ToString(
"dd-MM-yy_hh-mm"
);
byte
[] imageBytes = Convert.FromBase64String(data.Split(
','
)[1]);
//Save the Byte Array as Image File.
string
filePath = HttpContext.Current.Server.MapPath(
string
.Format(
"~/CapturedImage/{0}.jpg"
, fileName));
File.WriteAllBytes(filePath, imageBytes);
return
true
;
}
javascript code to capture image....
<script type=
"text/javascript"
>
$(
function
() {
Webcam.set({
width: 320,
height: 240,
image_format:
'jpeg'
,
jpeg_quality: 90
});
Webcam.attach(
'#webcam'
);
$(
"#btnCapture"
).click(
function
() {
Webcam.snap(
function
(data_uri) {
$(
"#imgCapture"
)[0].src = data_uri;
$(
"#btnUpload"
).removeAttr(
"disabled"
);
});
});
$(
"#btnCapture"
).click(
function
() {
$.ajax({
type:
"POST"
,
url:
"captureimage.aspx/SaveCapturedImage"
,
data:
"{data: '"
+ $(
"#imgCapture"
)[0].src +
"'}"
,
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
success:
function
(r) {
windo.close();
window.location.href =
'/studentpage.aspx'
;
}
});
});
});
</script>
This is my button code....
i have commented the as.net button.
<input type=
"button"
id=
"btnCapture"
value=
"Capture"
class
=
"buttondesign"
/>
<%--<asp:Button ID=
"btnCapture"
runat=
"server"
Text=
"Capture"
CssClass=
"buttondesign"
OnClick=
"btnCapture_Click1"
/>--%>
Reply
Answers (
1
)
Image is gone when selecting checkbox in C# Web Application.
Pass data between open C # Forms