我正在嘗試使用 AngularJs 將 base64 格式的資料轉換為影像,但出現錯誤,如果您能幫助我如何做,我將不勝感激。
$http({
method: 'GET',
url: '/Home/GetEmployeeDetail',
params: { ID: $scope.PersonID }
}).then(function (result) {
$scope.TC = result.data.TC;
$scope.Name = result.data.Name;
$scope.LastName = result.data.LastName;
$scope.DateOfBirth = new Date(result.data.DateOfBirth.match(/\d /)[0] * 1);
$scope.Email = result.data.Email;
$scope.Address = result.data.Address;
var base64 = result.data.Image;
console.log(base64);
var imgbase64 = atob(base64);
console.log(imgbase64);
var imglength = imgbase64.length;
var arrayBuffer = new ArrayBuffer(imglength);
var uintArray = new Uint8Array(arrayBuffer);
for (var i = 0; i < imglength; i ) {
uintArray[i] = imgbase64.charCodeAt(i);
}
$scope.img = uintArray;
<div class="profile-images" style="width:90px ; height:90px">
<img ng-src="{{img}}" />
</div
uj5u.com熱心網友回復:
您不需要對 base64 字串進行任何修改即可在 ng-src 中設定它。查看以下 plunkr:https ://plnkr.co/edit/WwnZ7mEvDXynb9M3
只需將字串直接從后端傳遞給 ng-src。
$http({
method: 'GET',
url: '/Home/GetEmployeeDetail',
params: { ID: $scope.PersonID }
}).then(function (result) {
var base64 = result.data.Image;
$scope.img = base64;
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/311585.html
