c#获取文件缩略图(位图),删除文件缩略图(位图)
发布时间:2024年01月08日
ImgFunction.deleteImg(gm.Path);
BitmapSource thumb = ImgFunction.getImg(gm.Path);
pop3grid.Background = new ImageBrush
{
ImageSource = thumb
};
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
public static BitmapSource deleteImg(string path)
{
try
{
if (!File.Exists(path))
{
return new BitmapImage(new Uri("pack://application:,,,/Images/null.png"));
}
ShellObject so = ShellFileSystemFolder.FromParsingName(path);
Bitmap bm = so.Thumbnail.Bitmap;
bm.MakeTransparent(System.Drawing.Color.Black);
BitmapSource img;
IntPtr hBitmap;
hBitmap = bm.GetHbitmap();
DeleteObject(hBitmap);
}
catch (Exception e)
{
}
return null;
}
public static BitmapSource getImg(string path)
{
if (!File.Exists(path))
{
return new BitmapImage(new Uri("pack://application:,,,/Images/null.png"));
}
ShellObject so = ShellFileSystemFolder.FromParsingName(path);
Bitmap bm = so.Thumbnail.Bitmap;
bm.MakeTransparent(System.Drawing.Color.Black);
BitmapSource img;
IntPtr hBitmap;
hBitmap = bm.GetHbitmap();
img = Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
return img;
}
文章来源:https://blog.csdn.net/u014018281/article/details/135456810
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!