Javascript AngularJS-将字节数组内容显示为图像

Javascript AngularJS-将字节数组内容显示为图像,javascript,angularjs,Javascript,Angularjs,我正在数据库中搜索一个字节数组形式的图像。我想使用标记图像将此内容显示为文件,但在这里不起作用 // Controller which get my image and put into $scope. function MyController($scope, $http, $location) { var url = '/json/FindImage?id=1'; $http.get(url).success(function(result) {

我正在数据库中搜索一个字节数组形式的图像。我想使用标记图像将此内容显示为文件,但在这里不起作用

// Controller which get my image and put into $scope.
function MyController($scope, $http, $location) {  

    var url = '/json/FindImage?id=1';  
    $http.get(url).success(function(result) {  
        $scope.image = result.Image;  
    }  
}  

// HTML
<!-- It doesn't work -->  
<img src="{{image}}" />  
<!-- It doesn't work also -->  
<img ng-src="{{image}}" />  
//获取我的映像并放入$scope的控制器。
函数MyController($scope,$http,$location){
var url='/json/FindImage?id=1';
$http.get(url).success(函数(结果){
$scope.image=result.image;
}  
}  
//HTML
有什么想法吗?
谢谢大家!

img的
src
属性指向图像的源文件,它不包含实际的源数据。你不能用这种方式做你想做的事情;相反,你必须用JavaScript编写图像解码器(例如,),输出到
画布
元素。

如果您可以让服务器以base64编码字符串返回图像,则可以使用作为src属性。

使用以下格式的
ng src

<img ng-src="data:image/JPEG;base64,{{image}}">

确保要返回以图像形式显示的数据已转换为 Tobase64字符串

在C#代码中,使用Convert.ToBase64String(imageBytes)并在视图中使用


获取数据:image/PNG;base64等.net::ERR\u无效\u URLme@Assem,甚至我也得到了net::ERR\u无效的\u URL。可能是什么问题。@赫玛,是的,实际上我想问题出在java端。现在在前端,我有一个ByteArrayOutputStream对象,我在b64中转换它,就像byte[]imageBytes=baos.toByteArray();String b64=Base64.encodeBase64String(imageBytes);baos.close();然后将我的字符串放在json.Hi@Assem Hafez中,应该在哪里添加清理文件器?@CiaranGallagher这应该放在您的配置angular.module('myApp').config(['$compileProvider',function($compileProvider){$compileProvider.aHrefSanitizationWhitelist(/^\s)中*(https?| file | ftp | blob):|数据:image\/);});
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ftp|blob):|data:image\//);