Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you for the reply. This is exactly what I was looking for, however ive run into a problem. Silverlight gives me the webcam snapshot as a WriteableBitmap type. Which I then tried to convert to a byte[] array before sending it over to MVC. It is saving to the database successfully, however it does not appear to be a valid image when I try to pull it back out from the database and display it. Is there an issue that you can see with my conversion code? Or perhaps can I send it over as an image type, or can I only send over byte[] arrays through http posts like this?</p> <p><strong>In my Silverlight application:</strong></p> <pre><code> private void SendImage() { var client = new WebClient(); var uri = new Uri("http://localhost:4600/GuestBadge/GetCameraImage"); client.OpenWriteCompleted += (sender, e) =&gt; { var buffer = (byte[])e.UserState; e.Result.Write(buffer, 0, buffer.Length); e.Result.Close(); }; client.OpenWriteAsync(uri, "POST", ToByteArray(SnapShot)); } public static byte[] ToByteArray(WriteableBitmap bmp) { // Init buffer int w = bmp.PixelWidth; int h = bmp.PixelHeight; int[] p = bmp.Pixels; int len = p.Length; byte[] result = new byte[4 * w * h]; // Copy pixels to buffer for (int i = 0, j = 0; i &lt; len; i++, j += 4) { int color = p[i]; result[j + 0] = (byte)(color &gt;&gt; 24); // A result[j + 1] = (byte)(color &gt;&gt; 16); // R result[j + 2] = (byte)(color &gt;&gt; 8); // G result[j + 3] = (byte)(color); // B } return result; } </code></pre> <p><strong>And in my controller:</strong></p> <pre><code> [HttpPost] public ActionResult GetCameraImage() { byte[] image = new byte[Request.InputStream.Length]; Request.InputStream.Read(image, 0, image.Length); var getPerson = (from a in db.Persons where a.PersonID == 3 select a).FirstOrDefault(); getPerson.Picture = image; db.SaveChanges(); return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload