[ad_1]
i am binding a base64 image to the UI.which is in a loop.but image is not binding,while inspect element i can c the image but not rendering
DBが戻ってこない
data:image/jpg;base64,
だから私はhtmlに追加しました
要素を検査中に取得しています
"data:image/jpeg;base64,/9j/4A
しかし、レンダリングされません。何かアイデアはありますか????
私が試したこと:
<pre><td> <span>{{ m.Name }}</span> </td> <td> <!--<img style="width:100px;height:100px" [src]="imageData1">--> <img [src]="'data:image/jpg;base64,'+m.ImageData" style="height:50px;width:50px" /> </td> <td> <span>{{m.Age }}</span>
解決策 1
使用 _sanitizer.bypassSecurityTrustUrl 角度の src 値が安全であることを伝える
以下のようにコードを変更できます。
DomSanitizer をインポートする
import { DomSanitizer } from '@angular/platform-browser';
この依存関係をコンストラクターに注入します
constructor(private domSanitizer: DomSanitizer) { }
myReader.onloadend = (e) => { this.base64Image = domSanitizer.bypassSecurityTrustUrl(myReader.result); console.log(this.base64Image); }
解決策 2
//Yes, /9j/4A decodes to the JPEG header ÿØÿà, but the rest of the binary data in the Base64 string is likely different. When a browser decodes the Base64 image data URL, it is expecting a proper JPEG image format with a valid header and no corruption. If the Base64 string contains binary data that does not correspond to a proper JPEG, the decoding will likely fail or result in a corrupted image or a blank page. Example: <!DOCTYPE html> <html> <head> <title>Display Image</title> </head> <body> <img style='display:block; width:32px;height:32px;' id='codeproject' src='data:image/jpeg;base64, /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAgACADAREAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAACAQHCQX/xAAcAQACAgIDAAAAAAAAAAAAAAAFCAQHBgkBAgP/2gAMAwEAAhADEAAAAUdqPfLOJ/kkVovE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