Save Silverlight webcam image (ImageSource) to Server

梦想的初衷 提交于 2019-12-08 04:28:05

问题


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.

  1. Create a WCF service on the server.
  2. Consume it on the silverlight client.
  3. Call service method to send an image to the server.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!