使用uni.chooseImage选择图片后获取到res.tempFilePaths[0]文件路径
使用canvas.draw(文件路径)
- 发布:2024-09-19 11:47
- 更新:2024-09-19 17:11
- 阅读:200
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows 10 专业版 22H2
HBuilderX类型: 正式
HBuilderX版本号: 4.24
手机系统: HarmonyOS NEXT
手机系统版本号: HarmonyOS NEXT Developer Beta1
手机厂商: 模拟器
手机机型: 模拟器
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
操作步骤:
预期结果:
没有报错
没有报错
实际结果:
E ERR_FAILED 报错了
E ERR_FAILED 报错了
bug描述:
canvas的draw方法跨域
E ERR_FAILED
Access to image at 'file://media/Photo/2/IMG_1726640213_001/922572c9cc214bb6a2dc83470a1b819.jpg' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, arkweb, data, chrome-extension, chrome, https, chrome-untrusted.
Access to image at 'file://media/Photo/2/IMG_1726640213_001/922572c9cc214bb6a2dc83470a1b819.jpg' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, arkweb, data, chrome-extension, chrome, https, chrome-untrusted.", source: resource://rawfile/apps/HBuilder/www/__uniappview.html (0)
1***@qq.com (作者)
uni.chooseImage({
count: 1,
success: (res=>{
let context = uni.createCanvasContext('mycanvas');
context.drawImage(res.tempFilePaths[0]);
context.draw();
})
})
2024-09-19 15:56
1***@qq.com (作者)
很简单的案例,就是使用uni.chooseImage获取图片途径,然后使用uni.createCanvasContext获取实例,调用方法,然后在鸿蒙开发工具的控制台打印了这句话Access to image at 'file://media/Photo/1/IMG_1725948676_000/9150e4e5gy1g08ooo4duoj205i05i3yl.jpg' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, arkweb, data, chrome-extension, chrome, https, chrome-untrusted.网上说是跨域了
2024-09-19 15:58
1***@qq.com (作者)
但是我不可能先上传到服务器返回在线链接再来画图吧,因为我的需求是裁图
2024-09-19 16:00