///<summary> ///Remove the backgroundcolor /// </summary> /// <param name="path"> the path of the file in string</param> public static BitmapImage RemoveBackGroundColor(string path, byte Red = 255, byte Green = 0, byte Blue = 255) { Bitmap myBitmap = BitmapImage2Bitmap(new BitmapImage(new Uri(path, UriKind.Absolute))); for (int i = 0; i < myBitmap.Width; i++) { for (int j = 0; j < myBitmap.Height; j++) { System.Drawing.Color c = myBitmap.GetPixel(i, j); if (c.R == Red && c.G == Green && c.B == Blue) { myBitmap.SetPixel(i, j, System.Drawing.Color.Transparent); } } } return(Bitmapp.ToBitmapImage(myBitmap)); }
public static void Create() { //MapImage = RemoveBackGroundColor("pack://application:,,,/Resources/Map.bmp",0,128,224); MapImage = new BitmapImage(new Uri("pack://application:,,,/Resources/map.bmp", UriKind.Absolute)); //MapImage2 = new BitmapImage(new Uri("pack://application:,,,/Resources/Mapdeel2.png", UriKind.Absolute)); //MapImage3 = new BitmapImage(new Uri("pack://application:,,,/Resources/Mapdeel3.png", UriKind.Absolute)); MapImageControl1.Source = MapImage; MapImageControl1.Stretch = Stretch.None; MapImageControl1.HorizontalAlignment = HorizontalAlignment.Left; MapImageControl1.VerticalAlignment = VerticalAlignment.Top; MapImageControl1.Margin = new Thickness(0, -1190, 0, 0); //MapImageControl2.Source = MapImage2; //MapImageControl2.Stretch = Stretch.None; //MapImageControl2.HorizontalAlignment = HorizontalAlignment.Left; //MapImageControl2.VerticalAlignment = VerticalAlignment.Top; //MapImageControl2.Margin = new Thickness(3298, -870, 0, 0); ////MapImageControl3.Source = MapImage3; //MapImageControl3.Stretch = Stretch.None; //MapImageControl3.HorizontalAlignment = HorizontalAlignment.Left; //MapImageControl3.VerticalAlignment = VerticalAlignment.Top; //MapImageControl3.Margin = new Thickness(7374, -870, 0, 0); int maxwidth = 16025; SVGParser.MaximumSize = new System.Drawing.Size((int)MapImage.Width, (int)MapImage.Height); DebugText(new Dictionary <string, string> { { "max width", MapImage.Height.ToString() } }); Bitmap bmp = SVGParser.GetBitmapFromSVG("E:/Jan Home/TestWPF/TestWPF/Resources/map.svg"); //BitmapImage temp = RemoveBackGroundColor("pack://application:,,,/Resources/map.tif",255,255,255); //MapImageControlSVG.Source = bmp; MapImageControlSVG.Source = Bitmapp.ToBitmapImage(bmp); MapImageControlSVG.Stretch = Stretch.None; MapImageControlSVG.HorizontalAlignment = HorizontalAlignment.Left; MapImageControlSVG.VerticalAlignment = VerticalAlignment.Top; MapImageControlSVG.Margin = new Thickness(0, -1190, 0, 0); MapImageControlSVG.Visibility = Visibility.Hidden; }