好的,我修改了几年前使用的一段代码……无论如何,它都需要更新……我本来可以稍微更改代码以添加额外的错误检查,但我决定不这样做……
我的代码是按照VBA实用程序建模的,该工具设计用于读取位图并将其逐像素写入用户控件。我不记得最初的来源(已经很多年了),所以如果有人知道它是谁,请告诉我,我很乐意将这个想法归功于他们
无论如何,我已将其更新为读取缩略图信息,并将其放入位图对象中,该对象可以分配给需要图像的任何控件。i、 例如图片盒、框架、表格等。我还添加了将背景颜色从缩略图中的默认白色切换为黑色(反之亦然)的功能,以及在需要时保存文件的功能
用法非常简单…
这将从文件名中的文件加载位图,并将背景色设置为黑色
- Dim imgMyImage As Image
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, False)
- Me.PictureBox1.Image = imgMyImage
其他选项:
- 'returns bitmap image exactly as it is in the file
- imgMyImage = acThumbnailReader.GetThumbnail(FileName)
- 'returns bitmap image exactly as it is in the file
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, True)
- 'returns bitmap image with inverted backcolor
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, False)
- 'returns bitmap image exactly as it is in the file and saves it as a temporary file in %temp%
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, True, True)
- 'returns bitmap image with inverted backcolor and saves it as a temporary file in %temp%
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, False, True)
- 'returns bitmap image exactly as it is in the file and saves it to a specified file
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, True, True, SaveNameWithPath)
- 'returns bitmap image with inverted backcolor and saves it to a specified file
- imgMyImage = acThumbnailReader.GetThumbnail(FileName, False, True, SaveNameWithPath)
只需将附加的类添加到您的VB.Net项目中
我会将其转换为C#,但已经晚了..也许明天
|