Angular - Display byte array as image

You need to convert your image data to a dataURL:

const reader = new FileReader();
reader.onload = (e) => this.image = e.target.result;
reader.readAsDataURL(new Blob([data]));

And in your component:

<img [src]="image"/>

Make sure you set the responseType to be of type 'blob' in your getImage() http get request.


You can display like this, it worked with me.

Import import { DomSanitizer } from '@angular/platform-browser';

Add DomSanitizer to constructor(private sanitizer: DomSanitizer) { }

this.cardBackgroundService.getImage(event.data.entitlementCertificateNumber, "C003")
.subscribe(data => {

  let objectURL = 'data:image/png;base64,' + data;
  this.image = this.sanitizer.bypassSecurityTrustUrl(objectURL);
});

In HTML

<img [src]='image' />