本文介绍了从C#字节数组和地方形象html标记使用AngularJS加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在字节数组形式的图像,从我是从下面的C#方法转化字节数组

I'm having an Image in the form of Byte Array, from that I'm converting Byte Array from the following C# method

public HttpResponseMessage ReturnBytes(byte[] bytes)
{
  HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
  result.Content = new ByteArrayContent(bytes);
  result.Content.Headers.ContentType = 
      new MediaTypeHeaderValue("application/octet-stream");

  return result;
}



我的HTML源代码:

My HTML Source Code:

<div ng-app="myApp" ng-controller="myCtrl">

<div id="div_image"></div>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
    $http.get("someurl")
    .then(function(response) {
        $scope.imageSrc = response.data;
        $('.div_image').html('<img src="data:image/png;base64,' + $scope.imageSrc + '" />');
    });
});
</script>



相关链接我按照:

Reference Links I have followed :




  • How to Get byte array properly from an Web Api Method in C#?
  • Display png image as response to jQuery ajax request

我不能能在HTML视图加载图像。请帮助我......

I Can't able to load the image in the HTML View. Kindly assist me...

推荐答案

发送图像而不是一个字节数组,但 Convert.ToBase64String 字节数组并发送文本。那么你的代码应工作。

Send your image not as a byte array, but Convert.ToBase64String the byte array and send as text. Then your code should work.

这篇关于从C#字节数组和地方形象html标记使用AngularJS加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 12:53