{html5} webgl下面跨域拉取图片的问题
来源:互联网 发布:球球代点刷棒棒源码 编辑:程序博客网 时间:2024/04/30 14:39
需要拉取微信用户头像并显示在游戏中,有两种方式:1)是使用xmlhttprequest 2)使用img.src=url。但这两种方式在webgl模式下面都不行。因为需要服务端配合设置Access-Control-Allow-Origin。而微信头像的服务器并没有设置,具体报错为:
Image from origin ‘http://wx.qlogo.cn’ has been blocked from loading by Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:7456’ is therefore not allowed access.
然而使用canvas绘制图片是可以的,因为webgl比canvas更严格,详情:
https://www.khronos.org/registry/webgl/specs/1.0/(搜索CORS):
WebGL necessarily imposes stronger restrictions on the use of cross-domain media than other APIs such as the 2D canvas rendering context, because shaders can be used to indirectly deduce the contents of textures which have been uploaded to the GPU.
WebGL applications may utilize images and videos that come from other domains, with the cooperation of the server hosting the media, using Cross-Origin Resource Sharing [CORS]. In order to use such media, the application needs to explicitly request permission to do so, and the server needs to explicitly grant permission. Successful CORS-enabled fetches of image and video elements from other domains cause the origin of these elements to be set to that of the containing Document [HTML].
var image = new Image();
// The onload handler should be set to a function which uploads the HTMLImageElement
// using texImage2D or texSubImage2D.
image.onload = …;
image.crossOrigin = “anonymous”;
image.src = “http://other-domain.com/image.jpg“;
现在只能用服务器转发了
- {html5} webgl下面跨域拉取图片的问题
- 基于HTML5 Canvas和WebGL实现图片的交互式几何变换
- 图片下面空隙问题
- html5+webgl 三维街景的渲染
- HTML5+webGL 多纹理的拼贴
- 基于HTML5和WebGL的碰撞测试
- [HTML5] 关于HTML5(WebGL)的那点事
- html5 canvas绘制图片模糊的问题
- html5 canvas绘制图片模糊的问题
- HTML5以及WebGL
- WebGL + HTML5 = ?
- HTML5以及WebGL
- Html5的局:WebGL的纹理格式的转换
- 八大疯狂的HTML5 Canvas及WebGL动画效果
- HTML5画布WebGL,文件Three.js控制的锥
- 基于HTML5的WebGL应用内存泄露分析
- 基于HTML5的WebGL设计汉诺塔3D游戏
- WebGL实现HTML5的3D贪吃蛇游戏
- ob_flush() 等相关,不需要等待脚本执行完,就输出数据
- Unity5中优化VR 应用的12个技巧(移动端)
- 解决eclipse/myeclipse控制台下中文乱码问题
- android 分享到微信朋友圈或微信好友
- java定时器
- {html5} webgl下面跨域拉取图片的问题
- "lambda"和“bind”的初步思考
- java 通过流的方式读取远程图片并显示在jsp页面(类型以jpg、png等结尾的图片)
- linux下错误修改了/etc/profile导致虚拟机无法登录
- Unity3d面试4
- 微信分享的两个问题
- java--数据结构--二叉树的最近公共祖先
- 平台免费接口,非常实用
- DEV express 控件 在 XE2下 无法编译,说没有dcu文件