问题
This is as far as I've gotten. What code would I write to save a captured image to the server? Without any dialog prompting for a save location. Similar to the way Facebook does it. (I've been unable to find examples online)
void CaptureSource_CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e)
{
capturedImage.ImageSource = e.Result;
stopCapture(); // turns off webcam
}
回答1:
It is not that simple.
- Create a WCF service on the server.
- Consume it on the silverlight client.
- Call service method to send an image to the server.
- Save it on the server with custom logic.
Or, if this is too complicated - follow this tutorial. It is rather compact RESTful approach demo.
回答2:
I did i before, Firstly ImageTools is good library not must but a good library, you may use. Beside this you shoul check for permission for camera access. Then here is the code, Hope helps,
/Capture image part/
_captureSource.CaptureImageCompleted += ((s, args) =>
{
//some other stuffs
domainServiceObject.PR_PATIENTPHOTOs.Clear();
photo = new PR_PATIENTPHOTO();
ImageTools.ExtendedImage eimg=args.Result.ToImage();
var encoder=new ImageTools.IO.Png.PngEncoder();
Stream stream= eimg.ToStreamByExtension("png");
if (stream.Length > 512000)
{
eimg= ExtendedImage.Resize(eimg, 240, new NearestNeighborResizer());
stream = eimg.ToStreamByExtension("png");
}
/Reload Image Part/
//note photo.photo is byte[]
photo = domainServerObject.PR_PATIENTPHOTOs.FirstOrDefault();
if (photo != null)
{
using (MemoryStream ms = new MemoryStream(photo.PHOTO, 0, photo.PHOTO.Length))
{
ms.Write(photo.PHOTO, 0, photo.PHOTO.Length);
BitmapImage img = new BitmapImage();
img.SetSource(ms);
imagePatientPhoto.Source = img;
}
}
来源:https://stackoverflow.com/questions/9899533/save-silverlight-webcam-image-imagesource-to-server