Wait for the cornerstone tools to handle CornerstoneImageRendered event to capture the rendered image on the download dialog

This commit is contained in:
Evren Ozkan 2018-02-23 11:57:01 -05:00
parent e5ad7e15a7
commit 3c1e4c51cd

View File

@ -80,24 +80,27 @@ Template.imageDownloadDialog.onRendered(() => {
instance.updateViewportPreview = () => { instance.updateViewportPreview = () => {
instance.$viewportElement.one('CornerstoneImageRendered', (event, enabledElement) => { instance.$viewportElement.one('CornerstoneImageRendered', (event, enabledElement) => {
const formData = instance.form.value(); // Wait for the tools to handle CornerstoneImageRendered event
const image = instance.viewportPreview; Tracker.afterFlush(() => {
const type = 'image/' + formData.type; const formData = instance.form.value();
const quality = formData.type === 'png' ? 1 : formData.quality / 100; const image = instance.viewportPreview;
const dataUrl = instance.downloadCanvas.toDataURL(type, quality); const type = 'image/' + formData.type;
image.src = dataUrl; const quality = formData.type === 'png' ? 1 : formData.quality / 100;
const dataUrl = instance.downloadCanvas.toDataURL(type, quality);
image.src = dataUrl;
const $element = $(enabledElement.element); const $element = $(enabledElement.element);
let width = $element.width(); let width = $element.width();
let height = $element.height(); let height = $element.height();
if (width > 512 || height > 512) { if (width > 512 || height > 512) {
const multiplier = 512 / Math.max(width, height); const multiplier = 512 / Math.max(width, height);
height *= multiplier; height *= multiplier;
width *= multiplier; width *= multiplier;
} }
image.width = width; image.width = width;
image.height = height; image.height = height;
});
}); });
}; };