I have a frequent change img src data, I bind it like this.
<img [src]="previewImage" alt="Preview Image" />
The previewImage
keeps changing in component in a loop like,
for (let i=0;i<Anumber;i++){
this.previewImage = "data:image/jpeg;base64,"+ this.hexToBase64(imageBytes) ;
}
Say the image data could change 10 times per second.
Now here comes the issue. According to my experience with Angular 4's data binding, as long as the data changed, it should reflect in the view. But for me it didn't work as expected, it loads the first image correctly, then it updates around each 20 seconds, it should be 10 frames per seconds, not 20 seconds a frame !
Either such process is extreme slow, like 20 seconds an update, or there is some problem I didn't know about image binding. Maybe it doesn't work like this for image data. BTW, each image could contain around 100k data.
So how to bind a frequent change image data in Angular?
Possible direction:
Using canvas instead of image, drawing the image directly on html. Will it be faster?
Maybe it's the angular change detection issue, when image data changes, angular didn't react immediately.
Maybe it's the image loading scheme, since my image data is base64 string, browser may take more time to load the image, how to avoid the image loading time?