c# wpf 加载图片问题。
答案:2 悬赏:30
解决时间 2021-03-22 22:19
- 提问者网友:宿醉何为情
- 2021-03-22 12:31
假设窗体图片的名字为image1,wpf 从后台通过BitmapImage加载图片到窗体。现在问题来了。。现在我想把BitmapImage转化Bitmap的格式。
最佳答案
- 二级知识专家网友:茫然不知崩溃
- 2021-03-22 12:37
图片闪烁是由于默认样式导致的,你需要重写其template。
网上一大堆的例子.前两天遇到了同样的问题,我遇到的是个button的背景图,放上去之后一直闪烁
margin="{templatebinding padding}" verticalalignment="{templatebinding verticalcontentalignment}"
snapstodevicepixels="{templatebinding snapstodevicepixels}" recognizesaccesskey="true"/>
网上一大堆的例子.前两天遇到了同样的问题,我遇到的是个button的背景图,放上去之后一直闪烁
snapstodevicepixels="{templatebinding snapstodevicepixels}" recognizesaccesskey="true"/>
全部回答
- 1楼网友:魅世女王
- 2021-03-22 13:59
private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
// BitmapImage bitmapImage = new BitmapImage(new Uri("../Images/test.png", UriKind.Relative));
using(MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapImage));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
return new Bitmap(bitmap);
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯