locked
how to reduce image resolution to post it in server in windows phone 8? RRS feed

  • Question

  • I want to reduce  the image  resolution to post it into server as base64 string as when i post large image it throw exception 

    DesertQueen

    Tuesday, January 28, 2014 4:26 AM

All replies

  • Hi,

    You need to send base64string in post method of webclient.In post method we can send  large data to server.

    Note:can you share your code how your tried to post,it may helpful for future answers!

    Tuesday, January 28, 2014 4:58 AM
  • Do you *want* to reduce resolution or do you want to know how to send large images?

    http://pauliom.wordpress.com

    Tuesday, January 28, 2014 6:31 AM
  •  PhotoChooserTask photo = new PhotoChooserTask();
                photo.ShowCamera = true;
                photo.Completed += photo_Completed;
                photo.Show();

    void photo_Completed(object sender, PhotoResult e)
            {
                if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
                {
                    img.Source =PictureDecoder.DecodeJpeg(e.ChosenPhoto);

    BitmapImage bm = new BitmapImage();
                    bm.SetSource(e.ChosenPhoto);
                    if (bm != null)
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            WriteableBitmap wbitmp = new WriteableBitmap(bm);
                            // Encode the screenshot as JPEG with a quality of 60%
                            wbitmp.SaveJpeg(memoryStream, wbitmp.PixelWidth, wbitmp.PixelHeight, 0, 60);
                            memoryStream.Seek(0, SeekOrigin.Begin);
                            img.Source = bm;
                            // Convert binary data to Base64 string
                            var bytes = memoryStream.ToArray();
                            string base64String = Convert.ToBase64String(bytes);

     memoryStream.Dispose();

    }

    }

    }

    }

     private readonly HttpClient _client = new HttpClient();

    public async Task Add(string newMeg, string Service_URL)
            {
              

     var jsonString = "{\"_Messages_Attachment\":\"" + newMeg +

     "}";
                    var content = new StringContent(jsonString);
                    var result = await _client.PostAsync(Service_URL, content);

    }


    DesertQueen

    Tuesday, January 28, 2014 9:22 PM
  • i want both to reduce resolution and to know  post large image 

    DesertQueen

    Tuesday, January 28, 2014 9:24 PM
  • To reduce resolution, just set the height and width to smaller values when you call SaveJpeg.
    Tuesday, January 28, 2014 9:37 PM
  • Can you change the server code, and/or does it support file chunking?

    http://pauliom.wordpress.com

    Tuesday, January 28, 2014 9:55 PM
  • So me code is correct and the problem  is from the server side (service that i post on )?

    DesertQueen

    Tuesday, January 28, 2014 9:58 PM