Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:49:19+00:00 2026-06-03T10:49:19+00:00

I have a utility that allows the user to take a camera photo and

  • 0

I have a utility that allows the user to take a camera photo and upload it, in addition to another option to upload a file. I’ve got most of it working, except for the part where I have to convert the webcam image to a jpg prior to upload. The code below has no error but produces invalid image data:

void CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e)
{
    busyIndicator.IsBusy = true;
    stopCapture();
    capturedImage.ImageSource = e.Result;

    ImageTools.ExtendedImage eimg = e.Result.ToImage();
    var encoder = new ImageTools.IO.Jpeg.JpegEncoder();

    Stream stream = eimg.ToStreamByExtension("jpg");

    //DO THIS LATER
    //if (stream.Length > 512000)
    //{
    //    eimg = ExtendedImage.Resize(eimg, 240, new NearestNeighborResizer());
    //    stream = eimg.ToStreamByExtension("jpg");
    //}

    encoder.Encode(eimg, stream);

    BitmapImage bitmap = new BitmapImage();
    bitmap.SetSource(stream);

    byte[] bytes = new byte[stream.Length];
    stream.Read(bytes, 0, (int)stream.Length);

    // picture file a class object to be used by uploader
    pictureFile.PictureName = "webcam.jpg";  // name will be changed later
    pictureFile.PictureStream = bytes;


    HtmlPage.Window.Invoke("gotDetails_WebCam", "");  // post page, then come back and do upload
}

Here is what PictureFile looks like:

[DataContract]
public class PictureFile
{
    [DataMember]
    public string PictureName { get; set; }

    [DataMember]
    public byte[] PictureStream { get; set; }
}

Can anyone figure out what I’m doing wrong to produce the bytes needed for a jpeg?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:49:23+00:00Added an answer on June 3, 2026 at 10:49 am

    good to see that you solved,

    here is my running code,
    I use png format,there is also file size check.
    Maybe it helps s.one else.

    dSrvPR is my Domain Service Class instance

    photo is an entity object in my EF.

    _captureSource.CaptureImageCompleted += ((s, args) =>
            {
                if (dSrvPR.PR_PATIENTPHOTOs.Count > 0 && photo != null)
                {
                    dSrvPR.PR_PATIENTPHOTOs.Remove(photo);
                }
    
                dSrvPR.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");
                }                     
                if (stream.Length <= 512001)
                {
                    BinaryReader binary = new BinaryReader(stream);
                    //Read bytes from the BinaryReader and put them into a byte array.
                    Byte[] file = binary.ReadBytes((int)stream.Length);
                    photo.ID = Guid.NewGuid();
                    photo.PHOTO = file;
                    photo.PHOTODATE = DateTime.Now;
                    photo.ISACTIVE = true;
                    //some more unrelated fields
                    dSrvPR.PR_PATIENTPHOTOs.Add(photo);
                    dSrvPR.SubmitChanges();
      //Msg succedded
                }
                else
                {
                    Util.alert(...,"file size exceeded! :)";
                }
    
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linux utility that parses structured input ( a text file ),
I have a question regarding the creation of a utility that executes another command.
I have an application that allows the user to send a picture. This picture
I have some code that gives a user id to a utility that then
I have an android app that allows users to take photos. In that effort,
I have a POJO named Person.java, is there any bash or utility that allows
I have a utility that I have written in VB.net that runs as a
I have a WinForms utility that I use constantly, and enhance regularly. Roughly one
I have a utility class that creates & returns a db connection: Public Shared
I have a utility class that needs to work on a generic Class but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.