用uniapp+cornerstone.js写个dcm影像显示的demo
时间: 2023-12-22 12:03:08 浏览: 153
基于uniapp 的demo
好的,以下是一个用uniapp+cornerstone.js写的简单的dcm影像显示的demo,您可以参考代码:
1. 首先在 `pages.json` 文件中添加页面配置:
```json
{
"pages": [
{
"path": "pages/dicom-viewer/dicom-viewer",
"style": {
"navigationBarTitleText": "DICOM Viewer"
}
}
]
}
```
2. 在 `pages` 目录下创建 `dicom-viewer` 目录,并添加 `dicom-viewer.vue` 文件,以下是文件内容:
```html
<template>
<view class="container">
<view class="header">
<text class="title">DICOM Viewer</text>
</view>
<view class="body">
<input type="file" class="input-file" @change="onFileChange" />
<canvas id="dicomImage"></canvas>
</view>
</view>
</template>
<script>
import 'cornerstone-core/dist/cornerstone.js';
import 'cornerstone-math/dist/cornerstoneMath.js';
import 'cornerstone-tools/dist/cornerstoneTools.js';
import 'cornerstone-wado-image-loader/dist/cornerstoneWADOImageLoader.js';
export default {
name: "DicomViewer",
data() {
return {
imageId: null,
};
},
methods: {
onFileChange(event) {
const file = event.target.files[0];
this.imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add(file);
cornerstone.loadImage(this.imageId).then((image) => {
cornerstone.displayImage(document.getElementById("dicomImage"), image);
});
},
},
};
</script>
<style scoped>
.container {
flex-direction: column;
height: 100%;
}
.header {
display: flex;
justify-content: center;
align-items: center;
height: 50px;
background-color: #007aff;
color: white;
}
.title {
font-size: 20px;
font-weight: bold;
}
.body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
flex: 1;
}
.input-file {
margin-bottom: 20px;
}
canvas {
border: 1px solid black;
}
</style>
```
3. 在 `main.js` 文件中添加以下代码:
```js
import Vue from "vue";
import App from "./App";
import "uni.css";
Vue.config.productionTip = false;
App.mpType = "app";
const app = new Vue({
...App,
});
app.$mount();
```
这样就完成了一个简单的dcm影像显示的demo,您可以在uniapp中运行此应用程序,并使用上传文件按钮选择DICOM文件进行测试。
阅读全文