Skip to content

Instantly share code, notes, and snippets.

@cloud0259
Created February 7, 2023 20:04
Show Gist options
  • Save cloud0259/2822f872f0c318d8875ade0492bc5466 to your computer and use it in GitHub Desktop.
Save cloud0259/2822f872f0c318d8875ade0492bc5466 to your computer and use it in GitHub Desktop.
Convert image from number[] to base64
<img [imageData]="imageAsNumberArray" />
import { Directive, ElementRef, Input } from '@angular/core';
import { Image } from '../../models/avis';
import {Buffer} from 'buffer';
@Directive({
selector: '[imageData]'
})
export class ImageDataDirective {
@Input() imageData!: Image;
constructor(private el: ElementRef) {}
ngOnChanges() {
this.el.nativeElement.src ='data:image/jpeg;base64,' + Buffer.from(this.imageData.data).toString('base64');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment