求 wpf按钮背景图片加载 比bitmapTobitmapIamage 更高效的方式

try-catch 2017-03-27 03:53:44
已知Properties.Resources._562333
目前采用的是 Bitmap 转 BitmapImage的方式。
BitmapImage bitmapImg = new BitmapImage();
bitmapImg.BeginInit();
//
bitmapImg.EndInit();
类似这种 有没有更快加载出来的。刚毕业不是很懂。求指教。
...全文
118 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
exception92 2017-03-27
  • 打赏
  • 举报
回复
BitmapImage image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; // 缓存到内存 image.UriSource = new Uri(filePath); image.EndInit(); imgThumbnail.Source = image 没有专门比较过
Forty2 2017-03-27
  • 打赏
  • 举报
回复
WPF比较通常的做法是把背景图像写在xaml里,比较少用代码来定义,比如: <Button.Background> <ImageBrush ImageSource="/My.png" /> </Button.Background> 你可以直接把My.png拉到你的WPF项目下,VS将把它放到程序资源里,你在设计时,就能看到图片。 用Bitmap转BitmapImage也没有大的问题,本地资源的加载一般都很快。

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧