1 Replies - 5218 Views - Last Post: 24 April 2011 - 07:57 PM

#1 fiftycy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 02-April 11

i get black image instead of the captured picture

Posted 06 April 2011 - 05:58 AM

hello guys i got some problems when i receive the image as byte[] on the webservice. The saved image on server directory is a black image. something goes wrong on the convertion maybe.

Thanking you in advance!

        void OnCameraCaptureTaskCompleted(object sender, PhotoResult args)
        {
            if (args.TaskResult == TaskResult.OK)
            {
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(args.ChosenPhoto);
 
                   // converts the bitmap to byte[]. the class i provided below
                uppicbyte = Face.Convertion.ConvertToBytes(bmp);
            }
        }

        private void btnupload_Click(object sender, RoutedEventArgs e)
        {
          
            try
            {
                Service1SoapClient conncl = new Service1SoapClient();
                conncl.uploadImgCompleted += new EventHandler<uploadImgCompletedEventArgs>(conncl_uploadImgCompleted);
                conncl.uploadImgAsync(uppicbyte);  //uppicbyte is the byte[] of the captured image
                
            }
            catch (Exception r)
            {
                MessageBox.Show(r.ToString());
            }

        }





This is the class where the convertion is processed

 public static class Convertion
    {
        public static byte[] ConvertToBytes(this BitmapImage bitmapImage)
        {         

            using (MemoryStream ms = new MemoryStream())
            {
                WriteableBitmap btmMap = new WriteableBitmap
                    (bitmapImage.PixelWidth, bitmapImage.PixelHeight);

                 // write an image into the stream
                Extensions.SaveJpeg(btmMap, ms, bitmapImage.PixelWidth, bitmapImage.PixelHeight, 0, 100);
                ms.Seek(0, 0);
                
                return ms.ToArray();
            }
        }

        
    }




Is This A Good Question/Topic? 0
  • +

Replies To: i get black image instead of the captured picture

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: i get black image instead of the captured picture

Posted 24 April 2011 - 07:57 PM

I would use a different conversion method. Once the photo capture is completed, make sure you do something like this:

byte[] b = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Read(b, 0, Convert.ToInt32(e.ChosenPhoto.Length));


That way, pass the byte array to the service and perform the conversion on the service side rather than on the phone.

Also, remember that on the emulator you will not be able to use a real camera, and the image that is received might be a dummy.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1