0

in my wp7 application i am selecting image from media library and i want to get base64 string of that image because i am sending it to my wcf service to create image on server. the code for getting base64 string is as follows:

void taskToChoosePhoto_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        fileName = e.OriginalFileName;
        selectedPhoto = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
        imgSelected.Source = selectedPhoto;
        int[] p = selectedPhoto.Pixels;
        int len = p.Length * 4;
        result = new byte[len]; // ARGB

        Buffer.BlockCopy(p, 0, result, 0, len);
        base64 = System.Convert.ToBase64String(result);
    }
}  

but at server this code creates image file but in the format is invalid. I cross validated the base64 string but i think app is giving wrong base64string what could be the reason please help to find out the problem.

ie.
  • 5,982
  • 1
  • 29
  • 44
DharaPPatel
  • 12,035
  • 9
  • 31
  • 49

1 Answers1

1

You are sending base64-encoded pixels on the server. I'm not sure that this is what you need. How about converting Stream to the base64 string?

var memoryStream = new MemoryStream();
e.ChosenPhoto.CopyTo(memoryStream);
byte[] result = memoryStream.ToArray();
base64 = System.Convert.ToBase64String(result);
ie.
  • 5,982
  • 1
  • 29
  • 44
  • yeah we can take base64 string this way but this generated string not creating the same image which we have selected from the phone at server. – DharaPPatel May 03 '12 at 11:05
  • 1
    then again, the server code could help us to understand the roots of the issue. – ie. May 03 '12 at 11:13
  • i think there isn't any problem in Service at server as i have tried to pass the static bas64 string from my app of any image to service and service creating that image. so the problem might lies in base64 string no ? – DharaPPatel May 03 '12 at 11:23