简体   繁体   English

使用.net Webservice发送以像素为单位的图像

[英]send image in pixels using .net webservice

i wrote a webservice for send image in pixels form. 我写了一个网络服务,以像素形式发送图像。 it is working fine but when we give large amount of data in parameter it do not take full data. 它工作正常,但是当我们在参数中提供大量数据时,它不会获取全部数据。 it take limited data or small image. 它需要有限的数据或小图像。 is this parameter limit? 这是参数限制吗? or How i give large data in parameter? 或我如何在参数中提供大数据?

Here is my code 这是我的代码

    [WebMethod]
    public XmlDocument testuploadimage(string image)
    {

        XmlDocument login = new XmlDocument();
        XmlDeclaration dec = login.CreateXmlDeclaration("1.0", null, null);
        login.AppendChild(dec);
        XmlElement root = login.CreateElement("CreateUser");
        login.AppendChild(root);

        try
        {

                string actFolder = Server.MapPath("~/Images/");
                string s = image.Replace(" ", string.Empty);


                string imgname = DateTime.UtcNow.ToString().Replace(" ", "").Replace("AM", "").Replace("PM", "").Replace("/", "").Replace("-", "").Replace(":", "") + ".png";
                //       string imgname = DateTime.UtcNow.ToString("yyyyMMddHHmm") + ".png";

                byte[] imageBytes = Convert.FromBase64String(image.Replace(" ","+"));
                MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
                // MemoryStream ms = new MemoryStream(imageBytes);
                // Convert byte[] to Image
                //  ms.Write(imageBytes, 0, imageBytes.Length);

                Image image2 = Image.FromStream(ms);
                image2.Save(actFolder + imgname);


                XmlElement root1 = login.CreateElement("uploaded");
                root1.InnerText = "true";
                root.AppendChild(root1);
                XmlElement root2 = login.CreateElement("path");
                root2.InnerText = "http://Myserver/HeritageWebServices/Images/" + imgname;
                root.AppendChild(root2);

                return login;

            }
            catch (Exception ex)
            {
                ErrLogMgr.LogErrorMessage(string.Format("{0}{1}", "testuploadimage() for the image :",
                                                       image), "testUploadimage Inputs",
                                                        ERRORSOURCE.CSASERVICE);
                XmlDocument cd = new XmlDocument();
                cd.LoadXml("<Message>" + ex + "</Message>");



                return cd;

Two things 两件事情

Try to change the maxRequestLength on the web.config file. 尝试更改web.config文件上的maxRequestLength。

i see that you are using base64 to send the image, you could try to compress the bytearray before convert it to base64, to reduce the image or try to convert to a more compressed image type (ej: bmp to png). 我看到您正在使用base64发送图像,您可以在将字节数组转换为base64之前尝试对其进行压缩,以减少图像或尝试将其转换为压缩程度更高的图像类型(例如:将bmp转换为png)。

regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM