有没有办法让编辑后的图像可以用javascript下载
嗨,我正在制作一个网络应用程序,它可以拍摄普通图像并帮助您编辑它 我想让下载的图像可以根据用户进行编辑有没有办法让编辑后的图像可以用javascript下载,javascript,image,web,download,Javascript,Image,Web,Download,嗨,我正在制作一个网络应用程序,它可以拍摄普通图像并帮助您编辑它 我想让下载的图像可以根据用户进行编辑 要下载图像,只需在下载链接中添加download属性。 在您的情况下,请执行downloadLink.setAttribute(“下载”、“下载”) 编辑: 好吧,我不太确定你的情况下该怎么做,但可能会有所帮助。 它解释了blob和对象URL,以及您将要做的: 为图像创建blob和对象URL 将下载属性指定给downloadLink 指定href属性作为blob URL 而且它有效 重要 您还
要下载图像,只需在下载链接中添加
download
属性。在您的情况下,请执行
downloadLink.setAttribute(“下载”、“下载”)
编辑:
好吧,我不太确定你的情况下该怎么做,但可能会有所帮助。 它解释了blob和对象URL,以及您将要做的:
downloadLink
href
属性作为blob URL请参阅和以获取更多信息谢谢您的回答,但我已经尝试过了,我希望通过用户所做的编辑使图像可以下载。感谢您为解决我的问题所做的努力,但我找不到解决我问题的方法。现在有帮助了吗?不要放弃:)。。有时,编码是令人沮丧的,因此在解决程序员在努力寻找答案后遇到的问题时也是如此。非常感谢兄弟,我明白了你的意思。如果我的答案对你有帮助,请投票并标记为已回答。。这对其他人帮助很大:)
> > This is the function for applying the filters on the user image.
function applyFilter() {
var computedFilters = "";
controls.forEach(function (item) {
computedFilters +=
item.getAttribute("data-filter") +
"(" +
item.value +
item.getAttribute("data-scale") +
") ";
});
image.style.filter = computedFilters;
downloadableImage.style.filter = computedFilters;
}
> > > Here I am adding the eventListener for showing the live editing image to the user.
userFile.addEventListener("change", function () {
const reader = new FileReader();
reader.addEventListener("load", () => {
localStorage.setItem("userImage", reader.result);
image.setAttribute("src", localStorage.getItem("userImage"));
downloadableImage.setAttribute("src", reader.result);
downloadLink.setAttribute("href", localStorage.getItem("userImage"));
});
reader.readAsDataURL(this.files[0]);
});