如果用HttpWebRequest和HttpWebResponse从服务器取图片,会触发图片变化。于是想到从IE缓存读取图片

参考https://www.cnblogs.com/yelaiju/archive/2010/10/01/1839860.html和https://blog.csdn.net/annkie/article/details/6065521http://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缓存读取图片的更多相关文章

  1. 最蛋疼的bug:读取图片缩略图(一定要在相冊查看下形成缓存)

    近期的一个连接服务端的应用.须要读取图片,一般供用户公布商品选择上传图片.初始的图片列表应该是缩略图.仅仅有确定了,才上传原图,OK不多说上代码 package edu.buaa.erhuo; imp ...

  2. SDWebImage缓存图片和读取图片

    NSString *urlStr: NSUrl *url = [NSURL URLWithString:urlStr]; //缓存图片 SDWebImageManager *manager = [SD ...

  3. Cocos2d-x 在缓存创建图片

    /* 加载图片资源到SpriteFrame缓存池*/     CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache( ...

  4. img src某个php文件输出图片(回复更改图片readfile读取图片等)

    在论坛我们经常看到一回复图片就更改等,这功能是怎么实现的呢,其实更验证码道理相同. 新建文件 randimage.php 加入以下代码: <?php $dir='../../images/'; ...

  5. nodejs进阶(4)—读取图片到页面

    我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...

  6. HTML中上传与读取图片或文件(input file)----在路上(25)

    input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...

  7. nodeJS基础08:读取图片

    1.读取图片 //server.js var http = require("http"); var readImage = require("./readImage&q ...

  8. opencv用imread( argv[1], 1)读取图片

    显示一幅图:主要是运用功能:imread namedWindow imshowimread:从字面意思我们就可以看懂,用来读取图片的:namedWindow:显然,我们也可以看到这是用来命名窗口名称的 ...

  9. Servlet从本地文件中读取图片,并显示在页面中

    import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...

随机推荐

  1. 回客科技 面试的 实现ioc 容器用到的技术,简述BeanFactory的实现原理,大搜车面试的 spring 怎么实现的依赖注入(DI)

    前言:这几天的面试,感觉自己对spring 的整个掌握还是很薄弱.所以需要继续加强. 这里说明一下spring的这几个面试题,但是实际的感觉还是不对的,这种问题我认为需要真正读了spring的源码后说 ...

  2. 【Java每日一题】20170323

    20170322问题解析请点击今日问题下方的“[Java每日一题]20170323”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...

  3. WPF实现主题更换的简单DEMO

    WPF实现主题更换的简单DEMO 实现主题更换功能主要是三个知识点: 动态资源 ( DynamicResource ) INotifyPropertyChanged 接口 界面元素与数据模型的绑定 ( ...

  4. Javascript 跨域知识详细介绍

    JS跨域知识总结: 在“跨域”一词经常性地出现以前,我们其实已经频繁地使用它了.如在A网站的img,src指向B网站的某一图片地址,毫无疑问,这在通常情况下都是能正常显示的(且不论防盗链技术):同样, ...

  5. angular 过滤器(日期转换,时间转换,数据转换等)

    (function() { 'use strict'; /** * myApp Module * * Description */ angular.module('myApp') .filter('i ...

  6. Android代码书写规范

    1.资源文件命名规则2.类名文件命名规则3.尽量少用枚举4.public方法.重要逻辑.主要类结构体必须注释,其他部分可自定注释5.提交代码必须描述清楚修改内容,如果一次提交内容过多,拆分功能进行多次 ...

  7. XBanner的简单使用轮播

    导入依赖 implementation 'jp.wasabeef:glide-transformations:3.0.1' implementation 'com.xhb:xbanner:1.2.2' ...

  8. django 与 Vue 的结合使用说明

    1.第一步有一个Django项目 先是创建一个Django项目 django-admin startproject demo 然后创建一个application应用 python manage.py ...

  9. Android内存优化(三)详解内存分析工具MAT

    前言 在这个系列的前四篇文章中,我分别介绍了DVM.ART.内存泄漏和内存检测工具的相关知识点,这一篇我们通过一个小例子,来学习如何使用内存分析工具MAT. 1.概述 在进行内存分析时,我们可以使用M ...

  10. 使用fiddler抓包手机请求数据

    1.启动Fiddler,打开菜单栏中的 Tools > Fiddler Options,打开“Fiddler Options”对话框. 2.在Fiddler Options”对话框切换到“Con ...