跨来源图像加载被拒绝-仅限iPhone-简单图像上传
Cross-origin image load denied - iPhone only - simple image upload
我正试图从iPhone上传一张图像,并多次使用该图像绘制到画布上,然后最终保存图像(尽管我还没有实现保存部分)。我在这里使用示例:http://code.hootsuite.com/html5/我可以只绘制图像,但是,如果我试图修改图像,我会得到交叉原点错误。图片上传和编辑适用于Chrome上的android设备(但不适用于Safari上的iPhone)。有没有人遇到过类似的问题,或者可以提供一些解决方案?
if (window.File && window.FileReader && window.FormData) {
var inputField = document.getElementById('file');
inputField.addEventListener('change', function(e){
var file = e.target.files[0];
if (file) {
if (/^image'//i.test(file.type)) {
readFile(file);
} else {
alert('Not a valid image!');
}
}
})
} else {
alert("FILE UPLOAD NOT SUPPORTED");
}
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function () {
console.log('reader.onloadend');
processFile(reader.result, file.type);
};
reader.onerror = function () {
alert('There was an error reading the file!');
};
reader.readAsDataURL(file);
}
function processFile(dataURL, fileType) {
var maxWidth = 600;
var maxHeight = 600;
var image = new Image();
image.src = dataURL;
image.onload = function () {
var width = image.width;
var height = image.height;
var shouldResize = (width > maxWidth) || (height > maxHeight);
main(image); // this passes image to function that draws image to canvas and crops
}
这似乎是iOS中基于webkit的浏览器的一个缺陷/限制。
至于解决方法:您可以尝试将图像上传为ArrayBuffer(readAsArrayBuffer()
),并创建一个Blob和一个对象url以设置为源。
有关详细信息,请参阅此答案。
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- 跨来源图像加载被拒绝-仅限iPhone-简单图像上传
- JPG图像不会显示在Safari PC / iPhone上
- 使用Phonegap将图像保存到Iphone照片库
- 如何在不丢失Jssor图像滑块的情况下更改其尺寸'其响应特性、图像纵横比等仅适用于iPhone设备
- iPhone谷歌图像搜索触摸事件功能是如何工作的
- 设备宽度的iphone上的mathJax产生图像字体
- 禁用iPhone“;保存图像”;弹出窗口
- Phonegap中的多屏幕支持和android、iphone、windows黑莓的图像大小
- 移动浏览器(iPad/iPhone/iPod/Android)在不断更新图像时崩溃
- 打开Youtube视频与图像在iPhone Safari HTML页面
- 如果删除不相关的脚本,使用html画布生成的Iphone图像将被裁剪
- 是否有一个好的jQuery (Javascript)库来做快速视频(不是图像)缩放/平移?(目标:iPhone通过Pho
- 我无法在iPhone上通过phonegap显示编码图像(Base64)
- 如何防止iPhone用户上传多个图像
- iPad/iPhone预加载图像时出错
- iPhone / iPad应用程序图像格式化最佳实践
- 如何阻止iPhone在上传到后端期间重新压缩图像