DownLoadImage

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Declare Function DeleteUrlCacheEntry Lib "wininet" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Sub DownloadImage(ByVal ImageUrl As String, ByVal ImagePath As String)
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, ImageUrl, ImagePath, 0, 0)
    If lngRetVal = 0 Then
        DeleteUrlCacheEntry ImageUrl  '清除缓存
        'MsgBox "成功"
    Else
        'MsgBox "失败"
    End If
End Sub

  

转载于:https://www.cnblogs.com/nextseven/p/7291766.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你使用 html2canvas 将元素转换为 canvas,并将 canvas 转换为图片 URL 后,你可以将图片下载到指定的地址,例如 D 盘 temp 文件夹中。你可以按照以下步骤进行操作: 1. 在你的 Vue.js 组件中创建一个方法来处理下载图片的逻辑,代码如下: ``` methods: { downloadImage() { // 获取需要下载的元素 const element = document.getElementById('image'); // 使用 html2canvas 将元素转换为 canvas html2canvas(element).then(canvas => { // 将 canvas 转换为图片 URL const imageUrl = canvas.toDataURL('image/png'); // 创建一个链接 const link = document.createElement('a'); // 将链接的 href 属性设置为图片 URL,并将 download 属性设置为文件名 link.href = imageUrl; link.download = 'image.png'; // 将链接添加到页面并点击下载 document.body.appendChild(link); link.click(); document.body.removeChild(link); // 将图片下载到指定的地址 const imageBlob = this.dataURItoBlob(imageUrl); const formData = new FormData(); formData.append('file', imageBlob, 'image.png'); const xhr = new XMLHttpRequest(); xhr.open('POST', 'http://localhost:3000/upload'); xhr.send(formData); }); }, dataURItoBlob(dataURI) { const byteString = atob(dataURI.split(',')[1]); const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; const ab = new ArrayBuffer(byteString.length); const ia = new Uint8Array(ab); for (let i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } return new Blob([ab], { type: mimeString }); } } ``` 2. 在 downloadImage 方法中,将图片下载到指定的地址。在这里,我将图片上传到一个本地服务器,代码如下: ``` // 将图片下载到指定的地址 const imageBlob = this.dataURItoBlob(imageUrl); const formData = new FormData(); formData.append('file', imageBlob, 'image.png'); const xhr = new XMLHttpRequest(); xhr.open('POST', 'http://localhost:3000/upload'); xhr.send(formData); ``` 在这里,我将图片转换为 Blob 对象,并使用 FormData 将其添加到请求体中,然后使用 XMLHttpRequest 发送 POST 请求将图片上传到本地服务器。 3. 最后,在你的服务器端代码中,你需要处理这个 POST 请求,并将图片保存到指定的地址,例如 D 盘 temp 文件夹中。这里我使用了 Node.js 和 Express 框架,代码如下: ``` const express = require('express'); const multer = require('multer'); const path = require('path'); const app = express(); // 设置上传文件的存储位置和文件名 const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'D:/temp') }, filename: function (req, file, cb) { cb(null, file.originalname) } }); // 创建上传文件的中间件 const upload = multer({ storage: storage }); // 处理上传文件的路由 app.post('/upload', upload.single('file'), function (req, res, next) { res.send('File uploaded successfully'); }); // 启动服务器 app.listen(3000, function () { console.log('Server started on port 3000'); }); ``` 在这里,我使用了 Multer 中间件来处理文件上传,并将上传的文件保存到 D 盘 temp 文件夹中。你可以根据自己的需求来修改代码。 这样,当用户点击下载按钮时,图片将被下载到本地文件系统中,并且上传到指定的地址。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值