How to Upload Image From Camera in Wpf

  • Kartik Vaghasiya
  • Updated date Aug 05, 2015
  • 45.4k
  • three

In this blog, I have explicate how we can upload photo and if photo not in PC. And so I will have photo from camera and save in database.

Step one: Create database and table your need.

Step 2: Create project in vs2012.

Stride 3: Create Entity Data Model. For more information read my previous blog.

Step 4: Create controller and view. Write code post-obit lawmaking in vie.

  1. <link href= "~/Content/bootstrap-fileupload.css"  rel= "stylesheet"  />
  2. <link href="~/Content/Photobooth.css"  rel= "stylesheet"  />
  3. <script src="~/Scripts/bootstrap-fileupload.js" ></script>
  4. <script src="~/Scripts/photowebcam.js" ></script>
  5. <style type="text/css" >
  6.     #example
  7.     {
  8.         acme:300px;
  9.     }
  10. </style>
  11. <divcourse = "pageheader" >
  12.     <divclass = "media" >
  13.         <divform = "pageicon pull-left" >
  14.             <iclass = "glyphicon glyphicon-cog" ></i>
  15.         </div>
  16.         <divclass = "media-trunk" >
  17.             <ulclass = "breadcrumb" >
  18.                 <li><a href="" ><i class = "glyphicon glyphicon-dwelling house" ></i></a></li>
  19.                 <li>Employee</li>
  20.             </ul>
  21.             <h4 id="lblSellertitle" >Add Employee</h4>
  22.         </div>
  23.     </div><!-- media -->
  24. </div>
  25. <divclass = "contentpanel" >
  26.     <grade method="postal service"  enctype= "multipart/course-data"  id= "AddEmployeeForm" >
  27.         <divclass = "col-doctor-12 form_align" >
  28.             <divclass = "form-grouping last" >
  29.                         <characterizationform = "command-characterization col-md-4"  id= "lblAvtar"  manner= "text-marshal: get-go" >Profile Picture</label>
  30.                         <divform = "col-doc-8" >
  31.                             <divclass = "fileupload fileupload-new"  data-provides= "fileupload" >
  32.                                 <divclass = "fileupload-new thumbnail"  style= "width: 200px; acme: 150px;" >
  33.                                     <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+epitome"  alt= ""  id= "imgcamera" >
  34.                                 </div>
  35.                                 <divclass = "fileupload-preview fileupload-exists thumbnail"  mode= "max-width: 200px; max-elevation: 150px; line-pinnacle: 20px;" ></div>
  36.                                 <div>
  37.                                     <spanclass = "btn btn-white btn-file" >
  38.                                         <spanclass = "fileupload-new" ><i class = "fa fa-paper-prune" ></i>Select image</bridge>
  39.                                         <spancourse = "fileupload-exists" ><i course = "fa fa-undo" ></i>Alter</span>
  40.                                         <input type="file"  name= "file" grade = "default"  id= "txtAvtar"  />
  41.                                     </span>
  42.                                     <a href="#" class = "btn btn-danger fileupload-exists"  data-dismiss= "fileupload" ><i class = "fa fa-trash" ></i>Remove</a>
  43.                                 </div>
  44.                             </div>
  45.                                <button type="button" course = "btn btn-primary btn-sm"  id= "btnbtncameraupload"  style= "width:150px;" >Upload from camera</button>
  46.                         </div>
  47.                     </div>
  48.    </div>
  49.    </div>
  50. <script>
  51.     $("#btnbtncameraupload" ).click(function () {
  52. if  ($( "#example" ).css( 'brandish' ) == 'none' ) {
  53.             $("#example" ).show();
  54.             $('#example' ).photobooth().on( "image" , function ( upshot , dataUrl) {
  55.                 $("#imgcamera" ).attr( 'src' , dataUrl);
  56.                 $("#pp" ).val(dataUrl);
  57.             });
  58.             $('#example' ).data( "photobooth" ).resize(400, 300);
  59.         }
  60.     });
  61. </script>

S tep 5: Delight insert the following js file in project. For js you tin go to. http://wolframhempel.github.io/photobooth-js and download. Js file.And for bootstrap-fileupload.js you tin can become this link.

  1. <script src= "~/Scripts/bootstrap-fileupload.js" ></script>
  2. <script src="~/Scripts/photowebcam.js" ></script>

Step 6: Write the following code in controller. For the post method.

  1. [AcceptVerbs(HttpVerbs.Mail)]
  2. public  ActionResult AddEmployee(usr_User UserNewAdd, HttpPostedFileBase file, FormCollection fc)
  3. {
  4.     Random objrandom =new  Random();
  5. cord  Password = Convert.ToString(objrandom.Next());
  6. if  (UserNewAdd.ProfilePicture != cypher  && file == null )
  7.     {
  8.         UserNewAdd.ProfilePicture = UserNewAdd.ProfilePicture.Supercede("data:paradigm/png;base64," , "" );
  9. string  base64 = UserNewAdd.ProfilePicture.Substring(UserNewAdd.ProfilePicture.IndexOf( ',' ) + 1);
  10.         base64 = base64.Trim('\0' );
  11. byte [] chartData = Catechumen.FromBase64String(base64);
  12.         CreateImage(chartData, UserNewAdd.EmailID.ToString() +".png" );
  13.         UserNewAdd.ProfilePicture = UserNewAdd.EmailID.ToString() +".png" ;
  14.     }
  15. if  (file != nothing )
  16.     {
  17.         var ProfPicName = Path.GetFileName(file.FileName);
  18.         var path = Path.Combine(Server.MapPath("~/ProfilePicture/" ), ProfPicName);
  19.         file.SaveAs(path);
  20.         UserNewAdd.ProfilePicture = file.FileName;
  21.     }
  22. if  (fc[ "languge" ] != null )
  23.     {
  24.         String languageKnownList = fc["languge" ].ToString();
  25.         UserNewAdd.LanguageKnown = languageKnownList;
  26.     }
  27.     UserNewAdd.UserID = Guid.NewGuid();
  28.     UserNewAdd.Password = Password;
  29.     DateTime UserDOB =new  DateTime();
  30.     DateTime UserJoinDate =new  DateTime();
  31.     DateTime UserReleaveDate =new  DateTime();
  32. if  (fc[ "DOB" ] != null )
  33.     {
  34.         UserDOB = DateTime.ParseExact(fc["DOB" ], "MM/dd/yyyy" , CultureInfo.InvariantCulture);
  35.     }
  36. if  (fc[ "JoiningDate" ] != cipher )
  37.     {
  38.         UserJoinDate = DateTime.ParseExact(fc["JoiningDate" ], "MM/dd/yyyy" , CultureInfo.InvariantCulture);
  39.     }
  40. if  (fc[ "ReleavingDate" ] == nothing  || fc[ "ReleavingDate" ] == "" )
  41.     {
  42.         UserReleaveDate = Catechumen.ToDateTime(goose egg );
  43.     }
  44. else
  45.     {
  46.         UserReleaveDate = DateTime.ParseExact(fc["ReleavingDate" ], "MM/dd/yyyy" , CultureInfo.InvariantCulture);
  47.     }
  48.     UserNewAdd.DOB = UserDOB;
  49.     UserNewAdd.JoiningDate = UserJoinDate;
  50.     UserNewAdd.IsActive =simulated ;
  51.     UserNewAdd.RoleName = _dataContext.usr_Roles.Where(s = > s.RoleID == UserNewAdd.RoleID).SingleOrDefault().RoleName;
  52.     _dataContext.usr_Users.InsertOnSubmit(UserNewAdd);
  53.     usr_Address AddAddressDetail =new  usr_Address();
  54.     AddAddressDetail.AddressID = Guid.NewGuid();
  55.     AddAddressDetail.StreetOne = UserNewAdd.usrAddressList.StreetOne;
  56.     AddAddressDetail.StreetTwo = UserNewAdd.usrAddressList.StreetTwo;
  57.     AddAddressDetail.Landmark = UserNewAdd.usrAddressList.Landmark;
  58.     AddAddressDetail.Urban center = UserNewAdd.usrAddressList.Urban center;
  59.     AddAddressDetail.State = UserNewAdd.usrAddressList.Country;
  60.     AddAddressDetail.Country = UserNewAdd.usrAddressList.Country;
  61.     AddAddressDetail.UserID = UserNewAdd.UserID;
  62.     AddAddressDetail.AddressType ="Primary Address" ;
  63.     _dataContext.usr_Address.InsertOnSubmit(AddAddressDetail);
  64.     _dataContext.SubmitChanges();
  65. if  (UserNewAdd.usrAddressList.isper == true )
  66.     {
  67.         usr_Address PerAdress =new  usr_Address();
  68.         PerAdress.AddressID = Guid.NewGuid();
  69.         PerAdress.StreetOne = UserNewAdd.usrAddressList.streatone1;
  70.         PerAdress.StreetTwo = UserNewAdd.usrAddressList.steattwo1;
  71.         PerAdress.Landmark = UserNewAdd.usrAddressList.landmark1;
  72.         PerAdress.City = UserNewAdd.usrAddressList.city1;
  73.         PerAdress.State = UserNewAdd.usrAddressList.state1;
  74.         PerAdress.State = UserNewAdd.usrAddressList.country1;
  75.         PerAdress.UserID = UserNewAdd.UserID;
  76.         PerAdress.AddressType ="Permanent Accost" ;
  77.         _dataContext.usr_Address.InsertOnSubmit(PerAdress);
  78.         _dataContext.SubmitChanges();
  79.     }
  80. string  strLink = Catechumen.ToString(ConfigurationSettings.AppSettings[ "ApplicationPath" ]) + "/Login/Login?UserID="  + EncryptionedString(UserNewAdd.UserID.ToString());
  81.     Cord msg = SendEmailWithPasswordKey(UserNewAdd.FirstName +" "  + UserNewAdd.LastName, UserNewAdd.EmailID, Password, strLink);
  82. return  RedirectToAction( "EmployeeList" );
  83. }

Step 7: Now you lot can run project. And Select profile picture field. Select Image push. So yous tin select information technology into our Drive merely.

Step 8: If yous tin have new photo from camera so you lot can select Upload from photographic camera push button.(for this piece of work only if camera supported devise like laptop and mobile)

click uoload image

Step 9: Ask for Shared selected device.

upload image

Pace 10: And then camera start and Take moving picture to push last button on correct side.

upload image

Step 11: If y'all tin take picture it display in profile picture paradigm in form.

profile image

weaverearmis.blogspot.com

Source: https://www.c-sharpcorner.com/blogs/upload-or-take-photo-from-camera-in-mvc1

0 Response to "How to Upload Image From Camera in Wpf"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel