如何使用MVC 5中的角度js将字节数组加载到图像中

时间:2015-12-10 11:12:38

标签: javascript c# angularjs asp.net-mvc-5

控制器:

public async Task<ActionResult> LoadProductImage( long id, short width, short height )
        {                
                var byteArray = await _streamAceVqbzService.Proxy.DocumentByteArray_GetDataBy_IdAsync( id, width, height );

                return File( byteArray , "image/jpeg" );
            }    

Angular JS:

  getProductImage: function (imageId, width, height)
         {
             var deferred = $q.defer();
               $http.post('/Product/LoadProductImage', JSON.stringify({id:imageId,width:width,height:height})).success(deferred.resolve).error(deferred.reject);
                       return deferred.promise;
         }

     // Get product image. 
        $scope.loadProductImage = function (itemAttributes) 
         {
            var imageId = 0;
            $.each(itemAttributes, function (index, data)
            {
                if (data.AttributeId == 1000700 && data.DataXml != null)
                {
                    imageId = data.DataXml;
                    return false;
                }
            });
            productRepository.getProductImage(imageId, 200, 144).then(function (imageArrary) 
            {
                $scope.productImage = imageArrary;
            });
            return $scope.productImage = imageArrary;
        }

查看:

<img class="ui-corner-all img-responsive defaultImageSize" ng-src="data:image/jpeg;base64;{{loadProductImage(product.ItemAttributes)}}" />

0 个答案:

没有答案