Пример #1
0
		public Image InsertCanvasPositionedIcons (Canvas FramingCanvas, String IconFileName,
							double WidthPercentage, double HeightPercentage,
							double ImageWidthPercentage)
			{
			if (!File.Exists (IconFileName))
				return null;
			Image IconImage = new Image ();
			FramingCanvas.Children.Add (IconImage);
			FramingCanvas.UpdateLayout ();
			double ActCanvasHeight = FramingCanvas.ActualHeight;
			double ActCanvasWidth = FramingCanvas.ActualWidth;
			BitmapImage IconBitmap = new BitmapImage ();
			IconBitmap.BeginInit ();
			IconBitmap.UriSource = new Uri (IconFileName);
			IconBitmap.EndInit ();
			IconImage.Source = IconBitmap;
			IconImage.Width = ActCanvasWidth * ImageWidthPercentage / 100;
			IconImage.UpdateLayout ();
			double ActIconHeight = IconImage.ActualHeight;
			double ActIconWidth = IconImage.ActualWidth;
			Canvas.SetTop (IconImage, (((ActCanvasHeight * HeightPercentage) / 100) - (ActIconHeight / 2)));
			Canvas.SetLeft (IconImage, (((ActCanvasWidth * WidthPercentage) / 100) - (ActIconWidth / 2)));
			return IconImage;
			}
Пример #2
0
		public Image InsertCanvasPositionedPicture (Canvas FramingCanvas, String Base64Input,
							double LeftPercentage,
							double TopPercentage,
							double ImageWidthPercentage,
							double ImageHeightPercentage)
			{
			Image PictureImage = new Image ();
			FramingCanvas.Children.Add (PictureImage);
			FramingCanvas.UpdateLayout ();
			double ActCanvasHeight = FramingCanvas.ActualHeight;
			double ActCanvasWidth = FramingCanvas.ActualWidth;
			byte [] ImageBytes = System.Convert.FromBase64String (Base64Input);
			MemoryStream ImageDataStream = new MemoryStream ();
			ImageDataStream.Write (ImageBytes, 0, ImageBytes.Length);
			ImageDataStream.Seek (0, SeekOrigin.Begin);
			BitmapImage DrawingBitmap = new BitmapImage ();
			//DrawingBitmap.CacheOption = BitmapCacheOption.OnLoad;
			DrawingBitmap.BeginInit ();
			DrawingBitmap.StreamSource = ImageDataStream;
			DrawingBitmap.EndInit ();
			if (ImageWidthPercentage > 0)
				{
				DrawingBitmap.DecodePixelWidth = (int)(ActCanvasWidth * ImageWidthPercentage / 100);
				PictureImage.Width = ActCanvasWidth * ImageWidthPercentage / 100;
				}
			if (ImageHeightPercentage > 0)
				{
				DrawingBitmap.DecodePixelHeight = (int)(ActCanvasHeight * ImageHeightPercentage / 100);
				PictureImage.Height = ActCanvasHeight * ImageHeightPercentage / 100;
				}
			PictureImage.Source = DrawingBitmap;
			//PictureImage.Width = ActCanvasWidth * ImageWidthPercentage / 100;
			PictureImage.UpdateLayout ();
			//double ActIconHeight = PictureImage.ActualHeight;
			//double ActIconWidth = PictureImage.ActualWidth;
			Canvas.SetTop (PictureImage, ((ActCanvasHeight * TopPercentage) / 100));
			Canvas.SetLeft (PictureImage, ((ActCanvasWidth * LeftPercentage) / 100));
			return PictureImage;
			}