首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

!c# 怎么获取共享内存图片!

2012-08-03 
!!!c# 如何获取共享内存图片!!!网上搜了搜知道要调用windows的api,如下[DllImport(Kernel32.dll, CharSe

!!!c# 如何获取共享内存图片!!!
网上搜了搜知道要调用windows的api,如下
 [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]  
  public static extern IntPtr OpenFileMapping(int dwDesiredAccess, bool bInheritHandle, string lpName);


  [DllImport("kernel32.dll")]
  public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
  dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, IntPtr dwNumberOfBytesToMap);

可是MapViewOfFile函数返回的是一个IntPtr 类型数据,请问如何把它变成图片文件啊

谢谢大家!!



[解决办法]
IntPtr 是不能转换成图片的,这个是一个窗口的句柄,剪切板中的图片倒是可以用自带方法直接获取。
[解决办法]
可以参考 http://blog.csdn.net/gaozhigang/article/details/5622319
[解决办法]
.net 4.0里增加了对memory mapped file的支持,不用再调windows api了:

using System.IO.MemoryMappedFiles;

MemoryMappedFile file = MemoryMappedFile.OpenExisting("mapname");
MemoryMappedFileViewStream stream = file.CreateViewStream();

拿到了stream,读写应该不成问题

热点排行