改变画布的颜色 [英] Change color of canvas

查看:77
本文介绍了改变画布的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个Canvas,其中包含StackPanel.该面板包含图像,我想更改该图像的路径.

这是我的代码,可以正常工作.但是我的查询是,是否可以在功能循环之外更改该图像的路径?.

Hi All,

I have one Canvas which contain StackPanel. And that panel contains image and i want to change path of that image.

Here is my code which is working fine.But my query is, is it possible to change path of that image out of function loop?.

Load Image(String Name)
{
   panel = new StackPanel();
   panel.Orientation = Orientation.Vertical;
                        
   path = "pack://siteoforigin:,,/cam.jpeg";

   imgLoc = new Uri(path, UriKind.RelativeOrAbsolute);
   imgId = new BitmapImage(imgLoc);
   img = new Image();
   img.Source = imgId;
   img.Width = 15;
   img.Height = 15;
   img.HorizontalAlignment = HorizontalAlignment.Left;
                       
   panel.Children.Add(img);                       
   panel.ToolTip = Name;
   panel.DataContext = Name;

   double Xcoordinatee = (Convert.ToDouble(Xcoordinate) * ImageHolder.ActualWidth);
   double Ycoordinatee = (Convert.ToDouble(Ycoordinate) * ImageHolder.ActualHeight);

   //set camera's x-coordinate
   Canvas.SetLeft(panel, Xcoordinatee);
   //set camera's y-coordinate
   Canvas.SetTop(panel, Ycoordinatee);

   panel.Opacity = 0.85;

   panel.Width = img.Width;
   panel.Height = img.Height;

   //restrict dropped camera image to be in map image area
   if (Xcoordinatee + panel.Width > ImageHolder.Width)
   {
      Canvas.SetLeft(panel, ImageHolder.Width - panel.Width);
   }

   if (Ycoordinatee + panel.Height > ImageHolder.Height)
   {
      Canvas.SetTop(panel, ImageHolder.Height - panel.Height);
   }

   ImageHolder.Children.Add(panel);

推荐答案

不清楚您的循环条件


这篇关于改变画布的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆