wpf问题 wpf中使用image控件,显示图片,如何让图片的透明区域不响应鼠标事件(有颜色区域照常响应)。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 仅供参考// 公共变量System.Drawing.Bitmap bitmap = null;// Window_Loaded 事件代码// 前提 img.Source 是文件名或类似application://... 的资源字符串Uri uri = new Uri(img.Source.ToString());// 256 是我加载的 png 图片的大小BitmapImage bi = new BitmapImage();bi.BeginInit();bi.DecodePixelWidth = 256;bi.DecodePixelHeight = 256;bi.UriSource = uri;bi.EndInit();var memory = new System.IO.MemoryStream();BitmapEncoder encoder = new JpegBitmapEncoder();encoder.Frames.Add(BitmapFrame.Create(bi));encoder.Save(memory);bitmap = new System.Drawing.Bitmap(memory);// 根据像素颜色进行判断吧// 当然 如果图像发生了缩放 则需要进行重新计算private void img_MouseMove(object sender, MouseEventArgs e){ int x = (int)(e.GetPosition(img).X); int y = (int)(e.GetPosition(img).Y); Console.WriteLine("{0}, {1}", x, y); try { // 此处需要进行 x, y 是否超出图片大小的判断 // 我就偷懒了 System.Drawing.Color c = bitmap.GetPixel(x, y); Color cl = Color.FromArgb(c.A, c.R, c.G, c.B); rect.Fill = new SolidColorBrush(cl); } catch { }} http://stackoverflow.com/questions/3592404/irregular-png-buttons-click-event-in-wpf/3594911#3594911 c#组合框显示 c#怎样生成条码 c# 读取excel中数据 C# 操作 VF 数据库问题 请教单一客户端程序应该用什么数据库或档案格式? datagrid 与滚动条的关系 C#中有没有函数将二进制数转化为十六进制数 如何注册com+组件到GAC中 大神來幫幫忙重繪checkbox 急(需要帮助,再线) 为什么关于C#数据结构的书这么少? 怎样把XML文件导入到SQL某张表中?急··在线等··
// 公共变量
System.Drawing.Bitmap bitmap = null;// Window_Loaded 事件代码
// 前提 img.Source 是文件名或类似application://... 的资源字符串Uri uri = new Uri(img.Source.ToString());// 256 是我加载的 png 图片的大小
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.DecodePixelWidth = 256;
bi.DecodePixelHeight = 256;
bi.UriSource = uri;
bi.EndInit();var memory = new System.IO.MemoryStream();
BitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bi));
encoder.Save(memory);bitmap = new System.Drawing.Bitmap(memory);// 根据像素颜色进行判断吧
// 当然 如果图像发生了缩放 则需要进行重新计算
private void img_MouseMove(object sender, MouseEventArgs e)
{
int x = (int)(e.GetPosition(img).X);
int y = (int)(e.GetPosition(img).Y); Console.WriteLine("{0}, {1}", x, y); try
{
// 此处需要进行 x, y 是否超出图片大小的判断
// 我就偷懒了
System.Drawing.Color c = bitmap.GetPixel(x, y);
Color cl = Color.FromArgb(c.A, c.R, c.G, c.B);
rect.Fill = new SolidColorBrush(cl);
}
catch
{
}
}