Created
February 7, 2023 20:04
-
-
Save cloud0259/2822f872f0c318d8875ade0492bc5466 to your computer and use it in GitHub Desktop.
Convert image from number[] to base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img [imageData]="imageAsNumberArray" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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