简体   繁体   English

如何下载使用渲染的图像<img>标签?

[英]How can I download image which is rendered with <img> tag?

Let me explain my use case:让我解释一下我的用例:

I have a page, where I fetch the image by the url (from remote host) and display it.我有一个页面,我通过 url(从远程主机)获取图像并显示它。 Also, I have a button on the page.另外,我在页面上有一个按钮。 When clicked, the image should be downloaded.单击时,应下载图像。 I want to download the image without making any other remote calls.我想下载图像而不进行任何其他远程调用。

So overall I want to support two things with a single fetch of the image:所以总的来说,我想通过一次获取图像来支持两件事:

  • Customer should be able to see the rendered image on the page.客户应该能够在页面上看到渲染的图像。
  • Customer should be able to download the image by clicking the button.客户应该能够通过单击按钮下载图像。

Can you help me with how can I do that?你能帮我解决这个问题吗?

Did you see window.location.href?你看到 window.location.href 了吗? https://www.w3schools.com/js/js_window_location.asp https://www.w3schools.com/js/js_window_location.asp

in my reference project I was taking an image from the back end, making a URL.createObjectURL (img) and assigning a function to a button that simply does window.href.location = Processedimage on on: click.在我的参考项目中,我从后端拍摄了一张图像,制作了 URL.createObjectURL (img) 并将 function 分配给一个按钮,该按钮只需执行 Z05B8C74CBD96FBF2DE4C1A352702 上的 Z05B8C74CBD96FBF2DEFBF2DE4C1A352702.hlocation。 This way you can open the original image in another browser window, but again, I don't know how useful it will be.这样你就可以在另一个浏览器window中打开原图了,但是我不知道它会有多大用处。 it is however a possible solution然而,这是一个可能的解决方案

There is actually no way to download the img tag directly, but you could use insert the image in an <a> element Like:实际上没有办法直接下载 img 标签,但是您可以使用将图像插入到 <a> 元素中,例如:

<img src="img_src">
<a href="img_src" download>
</a>

Is this what you mean?你是这个意思吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从后端下载图像并将其显示在img标签中? - How would I download an image from my backend and display it in an img tag? 如何选择包含img的最外层标签作为直接子级 - How can I select outermost tag which contains img as direct child 我可以将页面重定向到图像以便可以在IMG标签中使用吗? - Can I redirect a page to an image so it'll work in an IMG tag? 我可以将图像从 img 标签上传到 firebase 存储吗 - Can I upload image to firebase storage from img tag 如何获取div的背景图像值并将其应用于img标签onclick的src值? - How can I get the background-image value of a div and apply it to the src value of an img tag onclick? 如何在html img标签中使用Java字符串图像对象-有可能吗? - How can I use a java string image object in a html img tag - Is it possible? 我该怎么做<img>点击时标签显示全尺寸图像,而该标签的href可以更改? - How can I make <img> tag show a full size image when clicked, while href of that tag can change? 如何使用onmouseover的嵌入标签替换img标签 - How can I replace img tag with embed tag onmouseover 上传其中的图片 <img> 标记到服务器 - Uploading an image which is within <img> tag to server 当我将图像上传到Firebase存储并检索下载URL并显示在img标签中时,它显示多次 - When I upload an image to firebase storage and retriving the download url and displaying in img tag but it is showing multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM