Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我能';t显示生成为字节[]的图像_C#_Angularjs_Image - Fatal编程技术网

C# 我能';t显示生成为字节[]的图像

C# 我能';t显示生成为字节[]的图像,c#,angularjs,image,C#,Angularjs,Image,我的控制器(ASP MVC): 角度控制器: getTimelineChart = function (codSap, revStr) { dataService.getTimelineChart($scope.dateFilter.dt1, $scope.dateFilter.dt2, function (result) { $scope.imageChart = "data:image/png;base64," + result; }); } 角度服务: g

我的控制器(ASP MVC):

角度控制器:

getTimelineChart = function (codSap, revStr) {
    dataService.getTimelineChart($scope.dateFilter.dt1, $scope.dateFilter.dt2, function (result) {
        $scope.imageChart = "data:image/png;base64," + result;
    });
}
角度服务:

getTimelineChart = function (tsInic, tsEnd, callback) {
    $http({
        url: '/OM_API/getTimelineChart',
        method: 'POST',
        data: {
            tsInic: tsInic,
            tsEnd: tsEnd
        }
    }).success(function (result, status, headers) {
        return callback(result);
    }).error(function (error) {
        return callback(error);
    });
}
我的html:

<div class="row">
    <img ng-src="{{imageChart}}" width="1331" height="360" />
</div>

根据我读过的代码应该允许我显示一个png图像。 出现错误:

当我调用服务时,结果如下所示

我错在哪里


谢谢。

使用MVC,您将其作为
文件返回,该文件将其视为真实文件,而不是Base 64编码的文件。你可以把它放在你的
ngsrc

首先,我不知道这是否是一个好的解决方案,我只知道它对我有效

我只有在用base-64编码时才得到显示图像。然后我更改了MVC的回复,如下所示:

 public String getTimelineChart(DateTime tsInic, DateTime tsEnd, string typeReq = "normal")
{
        var rep = new AfterSalesWind.Models.OM_Repository();
        var chart = rep.getTimelineChart(tsInic, tsEnd);

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        chart.SaveImage(ms, ChartImageFormat.Png);

        return Convert.ToBase64String(ms.ToArray());
}

好的,我已经删除了“data:image/png;base64”。错误已消失,但图像未显示=((此外,我已尝试从MVC返回ActionResult,但什么都没有…)我想不使用ajax。ajax是一个问题?我认为ng src指令允许使用ajax。此外,我需要显示图像(图表)当用户按下按钮时,我不能放弃ajax,对吗?不,您可以随时更改ng src-使用查询字符串值。请查看
$sce
服务。感谢您的回复。现在我对sanitaze html代码了解一点。我的解决方案不是通过$sce,而是以encode64字符串的形式发送图像
 public String getTimelineChart(DateTime tsInic, DateTime tsEnd, string typeReq = "normal")
{
        var rep = new AfterSalesWind.Models.OM_Repository();
        var chart = rep.getTimelineChart(tsInic, tsEnd);

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        chart.SaveImage(ms, ChartImageFormat.Png);

        return Convert.ToBase64String(ms.ToArray());
}