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

  • SEARCH
  • Home
  • 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 7534735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:06:17+00:00 2026-05-30T06:06:17+00:00

I’m developing an Android App that should send an image to my ASP.NET Web

  • 0

I’m developing an Android App that should send an image to my ASP.NET Web Service where the image will be saved as a file. I’ve seen a couple of ways to do this and I went for this one: convert the image to a byte array -> convert the byte array to a string -> send the string to the web service using KSOAP2 -> receive the String at the Web Service -> convert it to a byte array ->
Save it as an image:

IVtest = (ImageView)findViewById(R.id.carticon);
BitmapDrawable drawable = (BitmapDrawable) IVtest.getDrawable();
    Bitmap bitmap = drawable.getBitmap();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] data = baos.toByteArray();
    ImageView image=new ImageView(this);
    image.setImageBitmap(bmp);
    String strBase64 = Base64.encode(data);

Then I send strBase64 to the web service.
In the Web Service I have this:

public Image ConvertToImage(byte[] image)
{
    MemoryStream ms = new MemoryStream(image);
    Image returnImage = Image.FromStream(ms);
    return returnImage;
}

[WebMethod]
public String UploadImage(String image, String name)
{
    byte[] image_byte = Encoding.Unicode.GetBytes(image);
    Image convertedImage = ConvertToImage(image_byte);
    try {
        convertedImage.Save(Server.MapPath("generated_image.jpg"),     System.Drawing.Imaging.ImageFormat.Jpeg);
    } catch (Exception e) {
        return e.Message;
    }
    return "Success";
}

I get an error at this line: Image returnImage = Image.FromStream(ms);

This is the error I get:

SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: Parameter is not valid.
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at System.Drawing.Image.FromStream(Stream stream)
   at Service.ConvertToImage(Byte[] image) in e:\FTP\nvm\Service.asmx:line 1366
   at Service.UploadImage(String image, String name) in e:\FTP\nvm\Service.asmx:line 1374
   --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@437bf7b0

Thanks

  • 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-05-30T06:06:19+00:00Added an answer on May 30, 2026 at 6:06 am

    Seems like there is something iffy with your conversion from string to image. Also you are not disposing your stream which will leak memory.

    Try this instead:

    private Image Base64ToImage(string base64String)
        {
            // Convert Base64 String to byte[]
            byte[] imageBytes = Convert.FromBase64String(base64String);
            using (var ms = new MemoryStream(imageBytes, 0,
                                             imageBytes.Length))
            {
                // Convert byte[] to Image
                ms.Write(imageBytes, 0, imageBytes.Length);
                Image image = Image.FromStream(ms, true);
                return image;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.