WEBAPI部分

通过nuget安装Opencvsharp ,这部分用来图像处理

controller中写如下方法,我要对原图进行旋转使用了Opencv,如果不需要旋转可以注释代码

        [HttpGet(Name = "ShowImage")]
        public async Task<IActionResult> ShowImage(string FileName)
        {
            // return PhysicalFile(FileName, "image/jpeg");
            Mat mat = new Mat();
            mat = Cv2.ImRead(FileName);
            Cv2.Rotate(mat, mat, RotateFlags.Rotate90Counterclockwise);

          
            MemoryStream stream = mat.Clone().ToMemoryStream(Path.GetExtension(FileName));
            // using (FileStream fileStream = new FileStream(FileName, FileMode.Open)) 
            //{
            //    int len = (int)fileStream.Length;
            //    byte[] buf = new byte[len];
            //    fileStream.Read(buf, 0, len);
            //    stream = new MemoryStream();
            //    stream.Write(buf, 0, len);
            //}
            return await Task.FromResult<FileResult>(File(stream.ToArray(), "image/jpeg"));

        }

Vue前端部分

通过axios调用controller中的ShowImage

Html部分
		<el-col :span="3">
					<el-button type='primary' class="el-btn" @click="DrawImage">图片</el-button>
				</el-col>

			<el-row>
				<!-- <img :src="FoamImageFile"/> :fit="fits" style="width: 100px; height: 100px"-->
				<el-image :src="FoamImageFileURL" :preview-src-list="[FoamImageFileURL]" />
			</el-row>


script部分

let FoamImageFile = ref<any>('/assets/img/abc.bmp')  // 图片所所在目录地址
let FoamImageFileURL = ref<any>('http://localhost:8100/assets/img/abc.bmp') //url地址

const DrawImage = async () => {
	console.log('FoamImageFile ', FoamImageFile)
	await axios.get(global_const.WEBAPI + `LMI3DCamera/ShowImage`, {  //params参数必写 , 如果没有可传参数,传{}以 JSON.stringify(cmdParam1)
		params: { FileName: FoamImageFile.value }
	})
		.then(function (response) {
			console.log('DrawImage ok');
			console.log(response);

			console.log('response.request.responseURL');
			console.log(response.request.responseURL);
			FoamImageFileURL.value = response.request.responseURL

			console.log('FoamImageFile ', FoamImageFile)
			//FoamImageFile.value=response.data
			return response.data;
		})
		.catch(function (error) {
			//ElMessage.error(cmd + '命令执行异常!' + error)
			console.log(error);
		});
}

原文地址:https://blog.csdn.net/easyboot/article/details/134726436

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_36832.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注