C#从IE缓存读取图片
如果用HttpWebRequest和HttpWebResponse从服务器取图片,会触发图片变化。于是想到从IE缓存读取图片
参考https://www.cnblogs.com/yelaiju/archive/2010/10/01/1839860.html和https://blog.csdn.net/annkie/article/details/6065521和http://www.mamicode.com/info-detail-370382.html
代码如下:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text; namespace Common
{
class Program
{//从IE缓存复制图片到D盘
static void Main(string[] args)
{
System.Diagnostics.Process.Start(" http://www.baidu.com ");
System.Threading.Thread.Sleep();
//打开IE缓存目录
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
IECache i = new IECache();
//在网页上找到百度logo图片的url写在下面
string b = i.GetPathForCachedFile("https://www.baidu.com/img/bd_logo1.png");
Console.WriteLine(b);
//从缓存中将bd_logo1.png拷贝到D盘下
File.Copy(b, @"d:\bd_logo1.png", true);
Console.WriteLine("现在打开D盘目录看看bd_logo1.png吧");
Console.ReadKey(); }
public class IECache
{
[DllImport("Wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern Boolean GetUrlCacheEntryInfo(String lpxaUrlName, IntPtr lpCacheEntryInfo, ref int lpdwCacheEntryInfoBufferSize);
const int ERROR_FILE_NOT_FOUND = 0x2;
struct LPINTERNET_CACHE_ENTRY_INFO
{
public int dwStructSize;
IntPtr lpszSourceUrlName;
public IntPtr lpszLocalFileName;
// int CacheEntryType;
// int dwUseCount;
// int dwHitRate;
//int dwSizeLow;
// int dwSizeHigh; //System.Runtime.InteropServices.ComTypes.FILETIME LastModifiedTime;
//System.Runtime.InteropServices.ComTypes.FILETIME Expiretime;
// System.Runtime.InteropServices.ComTypes.FILETIME LastAccessTime;
//System.Runtime.InteropServices.ComTypes.FILETIME LastSyncTime;
//IntPtr lpHeaderInfo;
//readonly int dwheaderInfoSize;
//IntPtr lpszFileExtension;
//int dwEemptDelta;
}
// 返回 指定URL文件的缓存在本地文件系统中的路径
public string GetPathForCachedFile(string fileUrl)
{
int cacheEntryInfoBufferSize = ;
IntPtr cacheEntryInfoBuffer = IntPtr.Zero;
int lastError; Boolean result;
try
{
result = GetUrlCacheEntryInfo(fileUrl, IntPtr.Zero, ref cacheEntryInfoBufferSize);
lastError = Marshal.GetLastWin32Error();
if (result == false)
{
if (lastError == ERROR_FILE_NOT_FOUND)
return null;
}
cacheEntryInfoBuffer = Marshal.AllocHGlobal(cacheEntryInfoBufferSize);
result = GetUrlCacheEntryInfo(fileUrl, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSize);
lastError = Marshal.GetLastWin32Error();
if (result == true)
{
Object strObj = Marshal.PtrToStructure(cacheEntryInfoBuffer, typeof(LPINTERNET_CACHE_ENTRY_INFO));
LPINTERNET_CACHE_ENTRY_INFO internetCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO)strObj;
String localFileName = Marshal.PtrToStringAuto(internetCacheEntry.lpszLocalFileName); return localFileName;
}
else
return null;// file not found
}
finally
{
if (!cacheEntryInfoBuffer.Equals(IntPtr.Zero))
Marshal.FreeHGlobal(cacheEntryInfoBuffer);
}
}
}
}
}
C#从IE缓存读取图片的更多相关文章
- 最蛋疼的bug:读取图片缩略图(一定要在相冊查看下形成缓存)
近期的一个连接服务端的应用.须要读取图片,一般供用户公布商品选择上传图片.初始的图片列表应该是缩略图.仅仅有确定了,才上传原图,OK不多说上代码 package edu.buaa.erhuo; imp ...
- SDWebImage缓存图片和读取图片
NSString *urlStr: NSUrl *url = [NSURL URLWithString:urlStr]; //缓存图片 SDWebImageManager *manager = [SD ...
- Cocos2d-x 在缓存创建图片
/* 加载图片资源到SpriteFrame缓存池*/ CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache( ...
- img src某个php文件输出图片(回复更改图片readfile读取图片等)
在论坛我们经常看到一回复图片就更改等,这功能是怎么实现的呢,其实更验证码道理相同. 新建文件 randimage.php 加入以下代码: <?php $dir='../../images/'; ...
- nodejs进阶(4)—读取图片到页面
我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...
- HTML中上传与读取图片或文件(input file)----在路上(25)
input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...
- nodeJS基础08:读取图片
1.读取图片 //server.js var http = require("http"); var readImage = require("./readImage&q ...
- opencv用imread( argv[1], 1)读取图片
显示一幅图:主要是运用功能:imread namedWindow imshowimread:从字面意思我们就可以看懂,用来读取图片的:namedWindow:显然,我们也可以看到这是用来命名窗口名称的 ...
- Servlet从本地文件中读取图片,并显示在页面中
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...
随机推荐
- Xhprof graphviz Warning: proc_open() [function.proc-open]: CreateProcess failed, error code 解决方法
Xhprof在windows下点击[View Full Callgraph]调用graphviz软件时.警告Warning: proc_open() [function.proc-open]: Cre ...
- 新浪IP库地址
新浪IP库地址 http://int.dpool.sina.com.cn/iplookup/iplookup.php
- 史上最全python面试题详解 (二)(附带详细答案(关注、持续更新))
23.re的match和search区别? re.match()从开头开始匹配string. re.search()从anywhere 来匹配string. # 多行模式>>> re ...
- springboot之scheduled任务调度
springboot整合Scheduled可以方便的进行任务调度,话不多说,直接上代码 package com.rookie.bigdata; import org.springframework.b ...
- angular input 为file on-change 无效
l转自:https://blog.csdn.net/klo220/article/details/53331229 侵删 出现这个问题是因为input的type是file,这时如果用ng-change ...
- 解决在TP5中无法使用快递鸟的即时查询API
快递鸟的接口对接其实很简单,先去官网注册账号,登陆把基本信息填好,然后在产品管理中订购一下“物流查询”,免费,不过其他产品是收费,免费的有对接口调用频率限制,结合自己的应用流量够用就可以. 使用前复制 ...
- docker研究-2
容器和虚拟机都是一种虚拟化技术,两者的主要区别: 虚拟机占用资源多,启动慢,荣誉步骤多:而容器启动快,占用资源少,体积小.Docker 属于 Linux 容器的一种封装,提供简单易用的容器使用接口.它 ...
- vue 构建项目遇到的请求本地json问题
在本地测试的json没有问题,但是打包后,发现json 的路径不对了,变成了绝对路径 解决方法: 建立的json文件需要放置 根目录/static下.如项目名/static/data.json,这边 ...
- (后端)项目中的错误之java中判断字符里面含有某些字符
数据库的数据出现了数据错误.找到原因是因为代码里面Spring的判断所导致的.其实就是判断字符里有01,走这里,有02,走那里,全是if,但是是类似indexOf的那种判断,偏偏有一个数据是0102, ...
- 我的第一个远程代码库房:建立Github仓库 心得
一直想有一个自己的代码库,搞了两天终于搞定了,把自己的代码上传到github的愿望终于实现了,虽然仅仅是个开始. 在搭建的过程中,吸收了些知识,记录在这里,以作为分享. Git 和 Github 的区 ...