/// <summary> /// setzt das Bitmap und die Farben neu /// </summary> /// <param name="typ"></param> /// <param name="bmday"></param> public void SetBitmap(PolylineType typ, Bitmap bmday) { if (bmday.Width != 32 || bmday.Height > 31) { throw new Exception("Das Bitmap muß 32 breit sein und darf höchstens 31 hoch sein."); } if (Polylinetype != typ) { Polylinetype = typ; } switch (Polylinetype) { case PolylineType.Day1_Night2: case PolylineType.NoBorder_Day1: case PolylineType.NoBorder_Day1_Night1: XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY1TR); break; case PolylineType.Day2: case PolylineType.Day2_Night2: case PolylineType.NoBorder_Day2_Night1: XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY2); break; } BitmapHeight = (uint)bmday.Height; DayColor1 = XBitmapDay.GetColor(0); switch (typ) { case PolylineType.Day2: case PolylineType.Day2_Night2: case PolylineType.NoBorder_Day2_Night1: DayColor2 = XBitmapDay.Colors > 1 ? XBitmapDay.GetColor(1) : Color.CornflowerBlue; break; } switch (typ) { case PolylineType.NoBorder_Day1_Night1: case PolylineType.NoBorder_Day2_Night1: NightColor1 = DayColor1; break; case PolylineType.Day1_Night2: case PolylineType.Day2_Night2: base.NightColor1 = DayColor1; base.NightColor2 = DayColor2; break; } }
private PixMap GetDummyXPixMap(BitmapColorMode bcm, bool b4Day, PixMap old) { if (old != null) { if (old.Colormode != bcm) { switch (old.Colormode) { case BitmapColorMode.POLY1TR: old.ChangeColorMode(BitmapColorMode.POLY2); old.InvertBits(); old.SetNewColors(new Color[] { old.GetColor(0), Color.White }); // 2. Farbe einfach Weiß break; case BitmapColorMode.POLY2: old.ChangeColorMode(BitmapColorMode.POLY1TR); old.InvertBits(); old.SetNewColors(new Color[] { old.GetColor(0) }); break; } } return(old); } PixMap pic = new PixMap(32, 32, 2, bcm); if (b4Day) { pic.SetNewColor(0, DayColor1); if (bcm == BitmapColorMode.POLY2) { pic.SetNewColor(1, DayColor2); } } else { pic.SetNewColor(0, NightColor1); if (bcm == BitmapColorMode.POLY2) { pic.SetNewColor(1, NightColor2); } } return(pic); }
/// <summary> /// setzt die Bitmaps (falls nicht null) mit dem einfachstmöglichen BitmapColorMode /// </summary> /// <param name="bmday"></param> /// <param name="bmnight"></param> /// <param name="bOnlyGarminColors">Die jeweils nächstgelegene Garminfarbe verwenden?</param> public void SetBitmaps(Bitmap bmday, Bitmap bmnight, bool bOnlyGarminColors) { if (bmday == null) { throw new Exception("Wenigstens das Tag-Bitmap muß gesetzt werden."); } if (bmnight != null) { if (bmday.Width != bmnight.Width || bmday.Height != bmnight.Height) { throw new Exception("Beide Bitmaps müßen die gleiche Größe haben."); } } if ((bmday.Width > 255 || bmday.Height > 255) || (bmnight != null && (bmnight.Width > 255 || bmnight.Height > 255))) { throw new Exception("Das Bitmap darf höchstens 255x255 groß sein."); } BitmapColorMode cm = GetMinBitmapColorMode(GetMinBitmapColorMode(bmday), GetMinBitmapColorMode(bmnight)); ColormodeDay = cm; if (bmday != null) // sonst bleibt das alte bestehen { XBitmapDay = new PixMap(bmday, ColormodeDay); if (bOnlyGarminColors) { for (uint i = 0; i < XBitmapDay.Colors; i++) { XBitmapDay.SetNewColor(i, GraphicElement.GetNearestGarminColor(XBitmapDay.GetColor(i))); } } } if (bmnight != null) { XBitmapNight = new PixMap(bmnight, ColormodeDay); WithNightXpm = true; if (bOnlyGarminColors) { for (uint i = 0; i < XBitmapNight.Colors; i++) { XBitmapNight.SetNewColor(i, GraphicElement.GetNearestGarminColor(XBitmapNight.GetColor(i))); } } } else { XBitmapNight = null; WithNightXpm = false; } Width = XBitmapDay.Width; Height = XBitmapDay.Height; }
/// <summary> /// setzt der oder die 32x32-Bitmaps für die Darstellung /// </summary> /// <param name="typ"></param> /// <param name="bmday"></param> /// <param name="bmnight"></param> public void SetBitmaps(ColorType typ, Bitmap bmday, Bitmap bmnight = null) { if (bmday == null) { throw new Exception("Kein Bitmap angegeben."); } if (typ == ColorType.Day1 || typ == ColorType.Day1_Night1) { throw new Exception("Falscher Typ für eine Darstellung mit Bitmap."); } if (bmday.Width != 32 || bmday.Height != 32) { throw new Exception("Das Bitmap muß 32x32 groß sein."); } if (Colortype != typ) { Colortype = typ; } switch (typ) { case ColorType.BM_Day1: case ColorType.BM_Day1_Night1: case ColorType.BM_Day1_Night2: XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY1TR); DayColor1 = XBitmapDay.GetColor(0); break; case ColorType.BM_Day2: case ColorType.BM_Day2_Night1: case ColorType.BM_Day2_Night2: XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY2); DayColor1 = XBitmapDay.GetColor(0); DayColor2 = XBitmapDay.GetColor(1); break; } if (bmnight != null) { if (bmday.Width != bmnight.Width || bmday.Height != bmnight.Height) { throw new Exception("Beide Bitmaps müßen die gleiche Größe haben."); } switch (typ) { case ColorType.BM_Day1_Night1: case ColorType.BM_Day2_Night1: XBitmapNight = new PixMap(bmnight, BitmapColorMode.POLY1TR); NightColor1 = XBitmapNight.GetColor(0); break; case ColorType.BM_Day1_Night2: case ColorType.BM_Day2_Night2: XBitmapNight = new PixMap(bmnight, BitmapColorMode.POLY1TR); NightColor1 = XBitmapNight.GetColor(0); NightColor2 = XBitmapNight.GetColor(1); break; } } else { XBitmapNight = null; } }
public void Read(BinaryReaderWriter br) { try { Options = br.ReadByte(); // es folgen 1 bis max. 4 Farben und ev. 1 Bitmap switch (Colortype) // hier muss sicher noch überprüft werden, ob die Typen wirklich richtig interpretiert werden { case ColorType.Day1: colDayColor[0] = BinaryColor.ReadColor(br); break; case ColorType.Day1_Night1: colDayColor[0] = BinaryColor.ReadColor(br); colNightColor[0] = BinaryColor.ReadColor(br); break; case ColorType.BM_Day2: // 2 Farben + 1x Pixeldaten colDayColor = BinaryColor.ReadColorTable(br, 2); XBitmapDay = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br); break; case ColorType.BM_Day2_Night2: // 4 Farben + 1x Pixeldaten colDayColor = BinaryColor.ReadColorTable(br, 2); colNightColor = BinaryColor.ReadColorTable(br, 2); XBitmapDay = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br); XBitmapNight = new PixMap(XBitmapDay); XBitmapNight.SetNewColors(colNightColor); break; case ColorType.BM_Day1_Night2: // 3 Farben + 1x Pixeldaten colDayColor[0] = BinaryColor.ReadColor(br); colDayColor[1] = PixMap.TransparentColor; colNightColor = BinaryColor.ReadColorTable(br, 2); XBitmapDay = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br); XBitmapNight = new PixMap(XBitmapDay); XBitmapNight.ChangeColorMode(BitmapColorMode.POLY2); XBitmapNight.SetNewColors(colNightColor); break; case ColorType.BM_Day2_Night1: // 3 Farben + 1x Pixeldaten colDayColor = BinaryColor.ReadColorTable(br, 2); colNightColor[0] = BinaryColor.ReadColor(br); colNightColor[1] = PixMap.TransparentColor; XBitmapDay = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br); XBitmapNight = new PixMap(XBitmapDay); XBitmapNight.ChangeColorMode(BitmapColorMode.POLY1TR); XBitmapNight.SetNewColors(colNightColor); break; case ColorType.BM_Day1: // 1 Farbe + 1x Pixeldaten colDayColor[0] = colNightColor[0] = BinaryColor.ReadColor(br); colDayColor[1] = colNightColor[1] = PixMap.TransparentColor; XBitmapDay = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY1TR, br); break; case ColorType.BM_Day1_Night1: // 2 Farben + 1x Pixeldaten colDayColor[0] = BinaryColor.ReadColor(br); colDayColor[1] = PixMap.TransparentColor; colNightColor[0] = BinaryColor.ReadColor(br); colNightColor[1] = PixMap.TransparentColor; XBitmapDay = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY1TR, br); XBitmapNight = new PixMap(XBitmapDay); XBitmapNight.SetNewColors(colNightColor); break; } if (WithDayBitmap) { // sicherheitshalber nochmal die Bitmapfarben übernehmen DayColor1 = XBitmapDay.GetColor(0); if (XBitmapDay.Colors > 1) { DayColor2 = XBitmapDay.GetColor(1); } if (XBitmapNight != null) { NightColor1 = XBitmapNight.GetColor(0); if (XBitmapNight.Colors > 1) { NightColor2 = XBitmapNight.GetColor(1); } } } if (WithString) { Text = new MultiText(br); } if (WithExtendedOptions) // es folgen weitere (max. 2) Farben { ExtOptions = br.ReadByte(); switch (FontColType) { case FontColours.Day: colFontColour[0] = BinaryColor.ReadColor(br); break; case FontColours.Night: colFontColour[1] = BinaryColor.ReadColor(br); break; case FontColours.DayAndNight: colFontColour = BinaryColor.ReadColorTable(br, 2); break; } } } catch (Exception ex) { throw new Exception(string.Format("Fehler beim Lesen des Polygons 0x{0:x} 0x{1:x}: {2}", Type, Subtype, ex.Message)); } }