public static void GenerateBitmap(int dim, string path) { string loc = "Equator"; // loc: Equator Position pos = new Position(Position.LATITUDE_POS, 0, 0, 0, Position.LONGITUDE_POS, 0, 0, 0); // time: Now DateTime dt = DateTime.Now; UTCDate udt = new UTCDate(0, null, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); // set up constants Colors colors = new Colors(); string font_face = "Arial"; // generate base image GraphBitmap grbit = new GraphBitmap(true, dim, colors, font_face); Bitmap bitmap_plain = grbit.RenderBaseImage(pos, udt); // render current day Bitmap bitmap = grbit.RenderCurrentDay(bitmap_plain, pos, udt); // render caption CaptionInfo ci = new CaptionInfo(loc, pos, udt); bitmap = grbit.RenderCaption(ci); // save grbit.SaveBitmap(bitmap, path); }
private static void SaveImage(object sender, EventArgs args) { int dim = GetInt(GetValue(registry[Id.IMAGE_SIZE])); string location = ReadLocation(); Position pos = ReadPosition(); UTCDate? date = ReadDate(); Colors colors = GuiDiagram.colors; string font_face = GuiDiagram.font_face; if ((pos != null) && (date != null)) { UTCDate dt = date.Value; string filename = Formatter.FormatImgFilename(location, pos, dt); SaveFileDialog dlg = Widgets.GetSaveFileDialog(filename, Constants.ImageFileDesc, Constants.ImageFileFilter); DialogResult ans = dlg.ShowDialog(); filename = dlg.FileName; if (ans == DialogResult.OK) { bool caption_b = GetBool(GetValue(registry[Id.IMAGE_CAPTIONTOGGLE])); bool sun_b = GetBool(GetValue(registry[Id.IMAGE_SUNTOGGLE])); GraphBitmap grbit = new GraphBitmap(caption_b, dim, colors, font_face); Bitmap bitmap = grbit.RenderBaseImage(pos, dt); if (sun_b) bitmap = grbit.RenderCurrentDay(bitmap, pos, dt); if (caption_b) bitmap = grbit.RenderCaption(new CaptionInfo(location, pos, dt)); try { grbit.SaveBitmap(bitmap, filename); Controller.Report(new Message(Result.OK, "Saved image to: " + filename)); } catch { Controller.Report(new Message(Result.Fail, "Failed to save image to: " + filename)); } } } }