[OHIF-Viewers]医疗数字阅片-医学影像-数字胶片直接下载,不再弹窗进行设置
直接下载解决方案
ViewersextensionscornerstonesrccommandsModule.js
代码语言:javascript复制 showDownloadViewportModal: ({ viewports }) => {
// 改变尺寸
function doResize(width, height,el) {
if (width < 100)
width = 100
if (height < 100)
height = 100
el.style.width = width 'px';
el.style.height = height 'px';
cornerstone.resize(el);
}
const activeViewportIndex = viewports.activeViewportIndex;
const activeViewport = getEnabledElement(activeViewportIndex);
const enabledElement = cornerstone.getEnabledElement(activeViewport);
const viewport = Object.assign({}, enabledElement.viewport);
delete viewport.scale;
viewport.translation = {
x: 0,
y: 0,
};
const viewportElement = document.querySelector(".cornerstone-canvas-nn");
cornerstone.enable(viewportElement); // 初始化
// 插入数据
cornerstone.loadAndCacheImage(enabledElement.image.imageId).then(function(image) {
cornerstone.displayImage(viewportElement, image); //插入图片
cornerstone.setViewport(viewportElement, viewport);//设置视图,设置现在显示的状态,如旋转等
cornerstone.resize(viewportElement, true);//先自适应调整一次,保证视图完整
});
//插入数据后,再执行尺寸的改变
doResize(512,512,viewportElement) // 改变尺寸
console.log(viewportElement);
//延时
setTimeout(function () {
// alert('VIDEO HAS STOPPED');
console.log("延迟执行");
console.log(viewportElement.querySelector('canvas').toDataURL()); // 打印数据
// console.log(document.querySelector("#root > div.FlexboxLayout > div.main-content > div > div > div > div.cornerstone-canvas-nn > canvas").toDataURL()); //绝对地址定位
viewportElement.querySelector('canvas').toBlob(blob => {
const URLObj = window.URL || window.webkitURL;
const a = document.createElement('a');
a.href = URLObj.createObjectURL(blob);
a.download = 'imgs.jpg';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
cornerstone.invalidate(viewportElement); // 删除el,一定要删除,不然连续下载,因为原始尺寸会产生插入数据不完整
}, 500);
},
ViewersextensionscornerstonesrcOHIFCornerstoneViewport.js
此位置添加cornerstone-canvas-nn标签
测试过动态创建标签,但无法渲染出数据。document.createElement('div');
<div className={"cornerstone-canvas-nn"} style={{position: 'absolute',left: '9999px'}}> </div>