8 Replies - 3077 Views - Last Post: 03 April 2011 - 03:16 PM

#1 fiftycy  Icon User is offline

  • New D.I.C Head

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

image convertion and sending

Posted 02 April 2011 - 07:11 AM

hello guys !!

i would like some help about how to convert an image to memory stream or whatever and send it to a web service. The image is already captured from wp7 camera.
Thanking you in advance.

Adamos
Is This A Good Question/Topic? 0
  • +

Replies To: image convertion and sending

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: image convertion and sending

Posted 02 April 2011 - 08:19 AM

Which part do you need help with? Converting the image or sending it to a web service?
Was This Post Helpful? 0
  • +
  • -

#3 fiftycy  Icon User is offline

  • New D.I.C Head

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

Re: image convertion and sending

Posted 02 April 2011 - 08:29 AM

I ve great issues how to convert it. bmp.Save() and many other solutions are not supported on WP7. About sending it i think so am okay i ve made the method but okay am not sure if its working because i dont have the byte array to send it!! and check it!!
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: image convertion and sending

Posted 02 April 2011 - 10:07 AM

You will need to handle the Completed event for the Camera task.

So once you are handling that event, you can get the picture that was taken..

private void CameraCompleted(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        // the 300,300 are just test dimensions.  You may need
        //   to change these
        WriteableBitmap picture = new WriteableBitmap(300,300);
        picture.LoadJpeg(e.ChosenPhoto);

        byte[] pictureByteArray = picture.ToByteArray();

        // send the byte array to your web service
    }
}



That should work for you.
Was This Post Helpful? 0
  • +
  • -

#5 fiftycy  Icon User is offline

  • New D.I.C Head

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

Re: image convertion and sending

Posted 02 April 2011 - 12:17 PM

Thanks for the code but i ve got an error.

Error 2 'System.Windows.Media.Imaging.WriteableBitmap' does not contain a definition for 'ToByteArray' and no extension method 'ToByteArray' accepting a first argument of type 'System.Windows.Media.Imaging.WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)
Was This Post Helpful? 0
  • +
  • -

#6 fiftycy  Icon User is offline

  • New D.I.C Head

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

Re: image convertion and sending

Posted 03 April 2011 - 01:17 AM

I find an implementation which almost works.

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);

                return ms.ToArray();
            }
        }



Then i call it using

byte[] pictureByteArray = ConvertToBytes(bmp);





but now i have a problem with static


ERROR:
Error 1 Extension method must be defined in a non-generic static class

This post has been edited by fiftycy: 03 April 2011 - 01:18 AM

Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: image convertion and sending

Posted 03 April 2011 - 06:18 AM

Try this....

http://kodierer.blog...ilverlight.html
Was This Post Helpful? 0
  • +
  • -

#8 fiftycy  Icon User is offline

  • New D.I.C Head

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

Re: image convertion and sending

Posted 03 April 2011 - 11:30 AM

Thank you a lot but i find the solution!!!

First i ve create a static class and i put the method.
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);

                return ms.ToArray();
            }
        }
    }



and the i call it at the phone application class

uppicbyte = Face.Convertion.ConvertToBytes(bmp);


Was This Post Helpful? 1
  • +
  • -

#9 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 765
  • View blog
  • Posts: 5,095
  • Joined: 08-December 08

Re: image convertion and sending

Posted 03 April 2011 - 03:16 PM

On a sidenote, you might also want to take a lookherefor a practice I used to convert GIF to JPEG in order to use them on Windows Phone 7.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1