2

我正在尝试使用 Ajax 更新图像 scr,首先在控制器中:

 public ActionResult GenerateMIPImage(float pX = 0, float pY = 0, float pZ = 0)
    {
        FileContentResult result;
      ...
        im.SetViewPlane(new Point3D(pX, pY, pZ), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0));
   ...
        objImage = im.Bitmap(outputSize, PixelFormat.Format24bppRgb, m);
        using (var memStream = new MemoryStream())
        {
            objImage.Save(memStream, ImageFormat.Png);
            result = this.File(memStream.GetBuffer(), "image/png");
        }

        return result;
    }

我第一次使用以下方式显示图像:

<img src='<%=Url.Action("GenerateMIPImage")%>' alt="" id="dImage"/>

然后我使用这个 Ajax 来更改其中一个变量:

$('#Zup').click(function () {
                pointZF++;
                //                alert(pointZF);
                $.ajax({
                    url: '/Home/GenerateMIPImage',
                    type: 'POST',
                    data: {
                        pX: pointXF,
                        pY: pointYF,
                        pZ: pointZF
                    },
                    success: function (data) {
                        dImage.src = data;
                    },
                    error: function () {

                    }
                });
            });

图像消失,当它检查它的属性时,我得到:

http://localhost:59601/�PNG

我会很感激你的建议,在此先感谢。

4

2 回答 2

1

在您的 ajax 中,您尝试将 img 的 src 设置为图像数据而不是图像 uri。
而是将 img 的 src 设置为 ajax 请求的 url,将参数添加到地址,并在服务器端将请求方法从 post 更改为 get。

dImage.src = '/Home/GenerateMIPImage?'+$.param({
                    pX: pointXF,
                    pY: pointYF,
                    pZ: pointZF
                });
于 2013-04-21T07:53:58.650 回答
-1

请按以下方式更改您请求的数据部分

 data: JSON.stringify({
                    pX: pointXF,
                    pY: pointYF,
                    pZ: pointZF
                }),
于 2013-04-21T08:16:02.053 回答