dicom图像按颜色分两种,一种是彩图,一种是灰阶图。
1,彩图。
cornerstone.loadImage(ImageUrl)
.then(image => {
if(image.color){
imageData = image.getCanvas().toDataURL();
}
})
2,灰阶图。
var responseType = { responseType: "blob" };
that.getImg(
http://localhost:8042/instances/e668dcbf-8829a100-c0bd203b-41e404d9-c533f3d4/preview
",responseType).then(function (response){
that.blobToBase64(response).then(res => {
imageData = res;
imageData =imageData.substring(imageData.indexOf(",")+1);
})
})
public blobToBase64(blob) {
var that =this;
return new Promise((resolve, reject) => {
this.fileReader.onload = (e) => {
resolve(e.target.result);
};
// readAsDataURL
that.fileReader.readAsDataURL(blob);
that.fileReader.onerror = () => {
reject(new Error('文件流异常'));
};
});
}
async getImg(url: string,responseType:any) {
if(this.axiosInstance){
const response = await this.axiosInstance.get(url,responseType)
.catch(function (error) {
let msg = `Fetching '${this.axiosInstance.defaults.baseURL}${url}' failed: ${error.message}.}`
if (error.response) {
msg += `(${error.response.status})`
}
throw new Error(msg);
});
if (response) {
return response.data;
}
return null;
}
}