private void UpdatePlayers() { PlayerAdapter pa = new PlayerAdapter(); lstPlayers.Title = LangResources.CurLang.Players; lstPlayers.Columns = new List <ListColumn>() { new ListColumn(LangResources.CurLang.Name, 200), new ListColumn(LangResources.CurLang.Position_Short, 50), new ListColumn(LangResources.CurLang.Rating, 120) }; List <ListRow> rows = new List <ListRow>(); List <Player> players = (from p in pa.GetPlayers(SetupData.TeamData.UniqueID) orderby p.Position, p.PreferredSide select p).ToList(); foreach (Player p in players) { rows.Add(new ListRow(p.UniqueID, new List <object>() { p.DisplayName(PersonNameReturnType.LastnameInitial), pa.PositionAndSideText(p, true), GraphicUtils.StarRating(p.Stars) })); } lstPlayers.Rows = rows; lstPlayers.SelectionMode = SelectMode.HighlightAndCallback; lstPlayers.Callback_ItemClick = ShowPlayer; }
private void UpdateEmails() { EmailAdapter ea = new EmailAdapter(); lstEmails.Title = LangResources.CurLang.Emails; lstEmails.Columns = new List <ListColumn>() { new ListColumn(LangResources.CurLang.Unread, 35), new ListColumn(LangResources.CurLang.Date, 125), new ListColumn(LangResources.CurLang.Subject, 390) }; List <ListRow> rows = new List <ListRow>(); List <Email> emails = ea.GetEmails(SetupData.ManagerData.UniqueID); foreach (Email e in emails) { EmailViewable ev = ea.ConvertEmailToViewable(e); rows.Add(new ListRow(e.UniqueID, new List <object>() { (ev.Read ? null : GraphicUtils.StarRating(1)), ev.Date.ToString(LangResources.CurLang.DateFormat), ev.Subject })); } lstEmails.Rows = rows; lstEmails.SelectionMode = SelectMode.HighlightAndCallback; lstEmails.Callback_ItemClick = ShowEmail; }
public void TestAddAndRemoveMultipleImages() { var image1 = GraphicUtils.GetImageByDimensions(100, 100); var image2 = GraphicUtils.GetImageByDimensions(200, 200); var category1 = new CategoryManager().GetOrCreate(18, "Small Car"); var observations1 = new Observation[] { new Observation(category1, 0.9, new SKRect(image1.Width / 5, image1.Height / 4, image1.Width / 3, image1.Height / 2)), new Observation(category1, 0.9, new SKRect(image1.Width / 6, image1.Height / 7, image1.Width * 2 / 3, image1.Height * 3 / 4)) }; var category2 = new CategoryManager().GetOrCreate(19, "Large Boat"); var observations2 = new[] { new Observation(category2, 0.9, new SKRect(image2.Width / 5, image2.Height / 4, image2.Width / 3, image2.Height / 2)) }; const string name1 = "Image1.jpg"; const string name2 = "Image2.jpg"; var creationTime1 = DateTime.UtcNow; var creationTime2 = DateTime.UtcNow; var imageDao1 = DatabaseService.InsertOrUpdate(new ImageEntry(image1, name1, creationTime1, null, observations1)); var imageDao2 = DatabaseService.InsertOrUpdate(new ImageEntry(image2, name2, creationTime2, null, observations2)); DatabaseService.DeleteImage(imageDao1.Id); Assert.IsNull(DatabaseService.GetImage(imageDao1.Id)); CollectionAssert.AreEqual(imageDao2.Observations, DatabaseUtils.GetAllObservations().ToList()); }
private Font CreateOriginalFont() { string fontname = ""; int fstyle = 0; int fontsize = 10; for (int i = 0; i < DataGridView.Rows.Count; i++) { string pname = GetColumnValue("NAME", i).ToString(); if (pname == Translator.TranslateStr(560)) { fontname = GetColumnValue("VALUE", i).ToString(); } else if (pname == Translator.TranslateStr(563)) { Variant nvar = (Variant)GetColumnValue("VALUE", i); fontsize = nvar; } else if (pname == Translator.TranslateStr(566)) { fstyle = (Variant)GetColumnValue("VALUE", i); } } FontStyle nfstyle = GraphicUtils.FontStyleFromInteger(fstyle); Font nfont = new Font(fontname, fontsize, nfstyle); return(nfont); }
public override void DrawItem(DrawItemEventArgs e) { var item = Control.Items.Cast <PointOfSaleForm.ProductListBoxItem>().ElementAtOrDefault(e.Index); if (item == null) { return; } e.Graphics.SetClip(e.Bounds); var backColor = e.State.HasFlag(DrawItemState.Selected) ? ControlPaint.Light(ColorScheme.PrimaryColor, 0.05f) : e.BackColor; using (var brush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(brush, e.Bounds); } using (var sb = new SolidBrush(GraphicUtils.ForegroundColorForBackground(backColor))) { e.Graphics.DrawString(_translation.TranslateMultilineResult(item.TextValue), Control.Font, sb, e.Bounds.OffsetAndReturn(5, 0), _centerVerticalStringFormat); } e.Graphics.SetClip(Rectangle.Empty); }
private IEnumerable <Color> GeneratePalette() { if (Bitmap == null) { return(Enumerable.Empty <Color>()); } byte[] bgrData = null; switch (Width) { case 512: { var crop = new CroppedBitmap(Bitmap, new Int32Rect(0, 0, 412, 240)); bgrData = crop.GetBgr24Data(); break; } case 1024: { // It Has a 920 Version, but the Max data is 1008, bear with a little gray var crop = new CroppedBitmap(Bitmap, new Int32Rect(0, 0, 1008, 240)); bgrData = crop.GetBgr24Data(); break; } default: { bgrData = Bitmap.GetBgr24Data(); break; } } return(GraphicUtils.PaletteGen(bgrData, 20).Select(Extensions.ToMediaColor).ToList()); }
public static bool AlterGridOptions(Report nreport) { bool nresult = false; using (GridOptions ndia = new GridOptions()) { ndia.bcolor.BackColor = GraphicUtils.ColorFromInteger(nreport.GridColor); ndia.checkenabled.Checked = nreport.GridEnabled; ndia.textwidth.Text = Twips.TextFromTwips(nreport.GridWidth); ndia.textheight.Text = Twips.TextFromTwips(nreport.GridHeight); if (nreport.GridLines) { ndia.combostyle.SelectedIndex = 1; } else { ndia.combostyle.SelectedIndex = 0; } ndia.checkvisible.Checked = nreport.GridVisible; if (ndia.ShowDialog() == DialogResult.OK) { nreport.GridLines = (ndia.combostyle.SelectedIndex == 1); nreport.GridEnabled = ndia.checkenabled.Checked; nreport.GridWidth = Twips.TwipsFromText(ndia.textwidth.Text); nreport.GridHeight = Twips.TwipsFromText(ndia.textheight.Text); nreport.GridColor = GraphicUtils.IntegerFromColor(ndia.bcolor.BackColor); nreport.GridVisible = ndia.checkvisible.Checked; nresult = true; } } return(nresult); }
public void TestFromImage_DimensionsNotDivisibleByDefault(int width, int height) { var image = GraphicUtils.GetImageByDimensions(width, height); var chips = Chip.FromImage(image).ToList(); var numWidth = width / SharedConstants.DefaultChipWidth + 1; var numHeight = height / SharedConstants.DefaultChipHeight + 1; for (var i = 0; i < numWidth; i++) { var subWidth = i + 1 < numWidth ? SharedConstants.DefaultChipWidth : width % SharedConstants.DefaultChipWidth; for (var j = 0; j < numHeight; j++) { var subHeight = j + 1 < numHeight ? SharedConstants.DefaultChipHeight : height % SharedConstants.DefaultChipHeight; var left = i * SharedConstants.DefaultChipWidth; var top = j * SharedConstants.DefaultChipHeight; var expectedRegion = new SKRectI(left, top, left + subWidth, top + subHeight); var expectedPixels = GraphicUtils.GetPixelsByDimensions(subWidth, subHeight); Assert.AreEqual(expectedRegion, chips[i * numHeight + j].Region); Assert.AreEqual(expectedPixels, chips[i * numHeight + j].Pixels); } } }
private async void DrawKey(CovidWorldwideStats stats) { const int ICON_STARTING_X = 3; const int ICON_PADDING_Y = 3; const int TEXT_PADDING_Y = 3; const int TEXT_PADDING_X = 40; const int ICON_SIZE_PIXELS = 35; if (stats == null) { return; } if (!long.TryParse(stats.Recovered, out long recovered) || !long.TryParse(stats.Deaths, out long deaths) || !long.TryParse(stats.AllCases, out long allCases)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"CoronavirusWorldwideStatsAction > Could not convert deaths/all cases to integer Deaths: {stats.Deaths} All Case: {stats.AllCases}"); return; } // Get the recovery rate as a percentage double recoveryRate = (double)recovered / (double)allCases * 100; using (Bitmap img = Tools.GenerateGenericKeyImage(out Graphics graphics)) { int height = img.Height; int width = img.Width; float heightPosition = 10; string text; var font = new Font("Verdana", 22, FontStyle.Bold, GraphicsUnit.Pixel); var fontRecoveryTitle = new Font("Verdana", 20, FontStyle.Bold, GraphicsUnit.Pixel); var fontRecovery = new Font("Verdana", 30, FontStyle.Bold, GraphicsUnit.Pixel); Bitmap icon; using (icon = IconChar.Ambulance.ToBitmap(ICON_SIZE_PIXELS, Color.Orange)) { graphics.DrawImage(icon, new Point(ICON_STARTING_X, (int)heightPosition)); heightPosition = GraphicUtils.DrawStringOnGraphics(graphics, GraphicUtils.FormatNumber(allCases), font, Brushes.Orange, new PointF(TEXT_PADDING_X, heightPosition + +TEXT_PADDING_Y)); } heightPosition += ICON_PADDING_Y; using (icon = IconChar.SkullCrossbones.ToBitmap(ICON_SIZE_PIXELS, Color.Red)) { graphics.DrawImage(icon, new Point(ICON_STARTING_X, (int)heightPosition)); heightPosition = GraphicUtils.DrawStringOnGraphics(graphics, GraphicUtils.FormatNumber(deaths), font, Brushes.Red, new PointF(TEXT_PADDING_X, heightPosition + TEXT_PADDING_Y)); } heightPosition += ICON_PADDING_Y; heightPosition = GraphicUtils.DrawStringOnGraphics(graphics, "Recovered:", fontRecoveryTitle, Brushes.Green, new PointF(ICON_STARTING_X, heightPosition)); // Put percentage exactly in middle text = $"{(int)recoveryRate}%"; float stringWidth = GraphicUtils.CenterText(text, width, fontRecovery, graphics, ICON_STARTING_X); GraphicUtils.DrawStringOnGraphics(graphics, text, fontRecovery, Brushes.Green, new PointF(stringWidth, heightPosition)); await Connection.SetImageAsync(img); graphics.Dispose(); } }
/// <summary> /// Obtain graphic extent /// </summary> /// <param name="astream">Stream containing a bitmap or a Jpeg image</param> /// <param name="extent">Initial bounding box</param> /// <param name="dpi">Resolution in Dots per inch of the image</param> /// <returns>Size in twips of the image</returns> override public Point GraphicExtent(MemoryStream astream, Point extent, int dpi) { int imagesize; int bitmapwidth, bitmapheight; bool indexed; int numcolors, bitsperpixel; string palette; bitmapwidth = 0; bitmapheight = 0; astream.Seek(0, System.IO.SeekOrigin.Begin); if (!GraphicUtils.GetJPegInfo(astream, out bitmapwidth, out bitmapheight)) { bool isgif = false; astream.Seek(0, System.IO.SeekOrigin.Begin); GraphicUtils.GetBitmapInfo(astream, out bitmapwidth, out bitmapheight, out imagesize, null, out indexed, out bitsperpixel, out numcolors, out palette, out isgif); astream.Seek(0, System.IO.SeekOrigin.Begin); } if (dpi <= 0) { return(new Point(extent.X, extent.Y)); } extent.X = (int)Math.Round((double)bitmapwidth / dpi * Twips.TWIPS_PER_INCH); extent.Y = (int)Math.Round((double)bitmapheight / dpi * Twips.TWIPS_PER_INCH); return(new Point(extent.X, extent.Y)); }
public async Task ResizeImageWithOption() { var thumWidth = 152; var thumHeight = 164; var basePath = AppDomain.CurrentDomain.BaseDirectory; var inputPath = Path.Combine(basePath, "files", "flower.jpg"); var outputPath = Path.Combine(basePath, "files", "flower_tmb.jpg"); if (File.Exists(outputPath)) { File.Delete(outputPath); } var options = new ResizeOptions { Size = new Size(thumWidth, thumHeight), Mode = ResizeMode.Crop, Compand = true, Position = AnchorPositionMode.TopLeft }; await GraphicUtils.Resize(inputPath, outputPath, options, Extensions.GraphicUtils.ImageFormats.UnKnown, true); var image = Image.Load(outputPath); Assert.True(File.Exists(outputPath)); }
private Grid GeneratePlayerTitleBlock(Player p) { PlayerAdapter pa = new PlayerAdapter(); Maths u = new Maths(); Grid g; g = GenerateBlankBlockGrid(3, p.DisplayName(PersonNameReturnType.FirstnameLastname) + (Debugger.IsAttached ? string.Format(", ID: {0}", p.UniqueID.ToString()) : ""), 2); Grid.SetColumnSpan(g, 2); TextBlock t = new TextBlock(); t.Text = pa.PositionAndSideText(p, false); t.Style = Application.Current.FindResource("ListHeader") as Style; t.Margin = new Thickness(8, 0, 0, 0); Grid.SetColumn(t, 0); Grid.SetColumnSpan(t, 2); Grid.SetRow(t, 1); g.Children.Add(t); UiUtils.AddGridData(g, 0, 2, LangResources.CurLang.DateOfBirth, p.DateOfBirth.ToString(LangResources.CurLang.DateFormat) + string.Format(" (Age: {0})", u.CalculateAgeInGame(p.DateOfBirth))); StackPanel stars = GraphicUtils.StarRating(p.Stars); stars.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetColumn(stars, 3); Grid.SetColumnSpan(stars, 3); Grid.SetRow(stars, 0); g.Children.Add(stars); return(g); }
private void UpdateTeams() { LeagueID = LeaguePaging.Items[LeaguePaging.CurrentItem].ID; LeagueTeams = (from tl in ta.GetTeamsByLeague(LeagueID) orderby tl.Name select tl).ToList(); List <ListRow> rows = new List <ListRow>(); foreach (Team t in LeagueTeams) { //rows.Add(new ListRow(t.UniqueID, new List<object>() //{ // t.Name, // ta.AveragePlayerRating(t.UniqueID).ToString("0.00") //})); //double avgPlayer = ta.AveragePlayerRating(t.UniqueID); rows.Add(new ListRow(t.UniqueID, new List <object>() { t.Name, GraphicUtils.StarRating(ta.AveragePlayerRating(t.UniqueID) / 20) })); } lstTeams.Rows = rows; }
public void SetupTeam(bool WithLabels) { int FormationID = (MyTeam ? team.CurrentFormation : team.LastKnownFormation); Dictionary <int, TeamPlayer> picks = (MyTeam ? team.Players : team.LastKnownPick); FormationPaging.DisplayItem(FormationID); SetupFormationTemplate(FormationID); PlayerAdapter pa = new PlayerAdapter(); foreach (KeyValuePair <int, TeamPlayer> p in picks) { TeamPlayer tp = p.Value; Player player = pa.GetPlayer(tp.PlayerID); if (WithLabels) { StackPanel s = new StackPanel(); s.Orientation = Orientation.Horizontal; TextBlock playerLabel = new TextBlock(); playerLabel.Width = 150; playerLabel.Height = 30; playerLabel.Text = player.DisplayName(PersonNameReturnType.LastnameInitial); playerLabel.MouseMove += new MouseEventHandler(PlayerName_MouseMove); playerLabel.Tag = tp.PlayerID; playerLabel.VerticalAlignment = VerticalAlignment.Center; playerLabel.Cursor = Cursors.Hand; PlayerLabels.Add(playerLabel); s.Children.Add(PlayerLabels[PlayerLabels.Count - 1]); TextBlock playerPos = new TextBlock(); playerPos.Width = 60; playerPos.Height = 30; playerPos.Text = pa.PositionAndSideText(player, true); playerPos.VerticalAlignment = VerticalAlignment.Center; s.Children.Add(playerPos); s.Children.Add(GraphicUtils.StarRatingWithNumber(player.Stars)); //stkNames.Children.Add(PlayerLabels[PlayerLabels.Count - 1]); stkNames.Children.Add(s); playerLabel = null; } if (tp.Selected == PlayerSelectionStatus.Starting && tp.PlayerGridX > -1 && tp.PlayerGridY > -1) { MarkerText[tp.PlayerGridX, tp.PlayerGridY].Text = player.DisplayName(PersonNameReturnType.InitialOptionalLastname); MarkerText[tp.PlayerGridX, tp.PlayerGridY].Visibility = Visibility.Visible; PlayerGridPositions[tp.PlayerGridX, tp.PlayerGridY] = tp.PlayerID; } } ChangesNotSaved = false; }
public void TestConstructor() { var chip = GraphicUtils.GetChipByRegion(10, 20, 40, 50); var expectedRegion = new SKRectI(10, 20, 50, 70); var expectedPixels = GraphicUtils.GetPixelsByDimensions(40, 50); Assert.AreEqual(expectedRegion, chip.Region); Assert.AreEqual(expectedPixels, chip.Pixels); }
public IEnumerator OnSingleImageCached(byte[] bytes, string id, bool isAnimated, Action <EnhancedImageInfo> Finally = null, int forcedHeight = -1) { if (bytes.Length == 0) { Finally(null); yield break; } Sprite sprite = null; int spriteWidth = 0, spriteHeight = 0; AnimationControllerData animControllerData = null; if (isAnimated) { AnimationLoader.Process(AnimationType.GIF, bytes, (tex, atlas, delays, width, height) => { animControllerData = AnimationController.instance.Register(id, tex, atlas, delays); sprite = animControllerData.sprite; spriteWidth = width; spriteHeight = height; }); yield return(new WaitUntil(() => animControllerData != null)); } else { try { sprite = GraphicUtils.LoadSpriteRaw(bytes); spriteWidth = sprite.texture.width; spriteHeight = sprite.texture.height; } catch (Exception ex) { Logger.log.Error(ex); sprite = null; } } EnhancedImageInfo ret = null; if (sprite != null) { if (forcedHeight != -1) { SetImageHeight(ref spriteWidth, ref spriteHeight, forcedHeight); } ret = new EnhancedImageInfo() { ImageId = id, Sprite = sprite, Width = spriteWidth, Height = spriteHeight, AnimControllerData = animControllerData }; _cachedImageInfo[id] = ret; } Finally?.Invoke(ret); }
public override void DrawItem(SidebarControl c, Graphics g, Size itemSize, bool isSelected) { using (var sb = new SolidBrush(isSelected ? GraphicUtils.ForegroundColorForBackground(c.ColorScheme.SecondaryColor) : ForeColor)) { using (var format = new StringFormat { LineAlignment = StringAlignment.Center, }) { g.DrawString(Text, c.Font, sb, new Rectangle(SIDE_OFFSET, 0, itemSize.Width, itemSize.Height), format); } } }
protected override void OnRenderItem(RenderMenuItemEventArgs e) { using (var brush = new SolidBrush(ForeColor)) { GraphicUtils.DrawCenteredText( e.Graphics, Text, e.Font, Rectangle.FromLTRB(e.Rectangle.Left + textOffsetLeft, e.Rectangle.Top, e.Rectangle.Right, e.Rectangle.Bottom), ForeColor, horizontal: false); } }
private void SetupControl() { imgPitch.ImageSource = ImageResources.GetImage(ImageResourceList.Pitch); // Paging control for formations FormationAdapter fa = new FormationAdapter(); foreach (Formation f in fa.GetFormations()) { FormationPaging.Items.Add(new PagingItem() { ID = f.UniqueID, Name = f.Name }); } // Create empty circles inside the grid // Set the PlayerGridPositions to blanks for (int x = 0; x < GRIDWIDTH; x++) { for (int y = 0; y < GRIDHEIGHT; y++) { // --- Marker symbol --- Markers[x, y] = GraphicUtils.Shirt(); Markers[x, y].VerticalAlignment = VerticalAlignment.Center; Markers[x, y].HorizontalAlignment = HorizontalAlignment.Center; Markers[x, y].AllowDrop = true; Markers[x, y].Drop += new DragEventHandler(Marker_Drop); Markers[x, y].Tag = x.ToString() + "," + y.ToString(); Grid.SetColumn(Markers[x, y], x + 1); Grid.SetRow(Markers[x, y], 8 - y); grdPitch.Children.Add(Markers[x, y]); // --- Text --- MarkerText[x, y] = new TextBlock(); MarkerText[x, y].Text = ""; MarkerText[x, y].Visibility = Visibility.Hidden; MarkerText[x, y].Foreground = Brushes.White; MarkerText[x, y].FontSize = 12; MarkerText[x, y].FontFamily = new FontFamily("Roboto Black"); MarkerText[x, y].VerticalAlignment = VerticalAlignment.Center; MarkerText[x, y].HorizontalAlignment = HorizontalAlignment.Center; Grid.SetColumn(MarkerText[x, y], x + 1); Grid.SetRow(MarkerText[x, y], 8 - y); grdPitch.Children.Add(MarkerText[x, y]); PlayerGridPositions[x, y] = -1; } } }
public void TestFromImage_DimensionsLessThanDefault(int width, int height) { var image = GraphicUtils.GetImageByDimensions(width, height); var chips = Chip.FromImage(image).ToList(); Assert.AreEqual(1, chips.Count); var expectedRegion = new SKRectI(0, 0, width, height); var expectedPixels = GraphicUtils.GetPixelsByDimensions(width, height); Assert.AreEqual(expectedRegion, chips[0].Region); Assert.AreEqual(expectedPixels, chips[0].Pixels); }
private void SetColor(Color c) { BackColor = c; ForeColor = GraphicUtils.GetInvertedBlackWhite(c); if (FTextDisplayed) { Text = c.Name; } else { Text = ""; } }
public Shader(string vs, string fs) { prID = GL.CreateProgram(); if (vs != null) { GraphicUtils.LoadShader(vs, ShaderType.VertexShader, prID, out vsID); } if (fs != null) { GraphicUtils.LoadShader(fs, ShaderType.FragmentShader, prID, out fsID); } GL.LinkProgram(prID); attributes = new Dictionary <string, int>(); }
public IEnumerator TryCacheSpriteSheetImage(string id, string uri, ImageRect rect, Action <EnhancedImageInfo> Finally = null, int forcedHeight = -1) { if (_cachedImageInfo.TryGetValue(id, out var info)) { Finally?.Invoke(info); yield break; } if (!_cachedSpriteSheets.TryGetValue(uri, out var tex) || tex == null) { yield return(DownloadContent(uri, (bytes) => tex = GraphicUtils.LoadTextureRaw(bytes))); _cachedSpriteSheets[uri] = tex; } CacheSpriteSheetImage(id, rect, tex, Finally, forcedHeight); }
public void TestToMLMultiArray_DefaultDimensions() { var chip = GraphicUtils.GetChipByRegion(0, 0, SharedConstants.DefaultChipWidth, SharedConstants.DefaultChipHeight); var result = chip.ToMLMultiArray(); Assert.AreEqual(new nint[] { 1, 1, 3, SharedConstants.DefaultChipWidth, SharedConstants.DefaultChipHeight }, result.Shape); for (var i = 0; i < SharedConstants.DefaultChipWidth; i++) { for (var j = 0; j < SharedConstants.DefaultChipHeight; j++) { AssertMLMultiArrayEntry(chip.Pixels[i][j], result, i, j); } } }
public void TestAddImage() { var image = GraphicUtils.GetImageByDimensions(100, 100); var category = new CategoryManager().GetOrCreate(18, "Small Car"); const string name = "Image.jpg"; var creationTime = DateTime.UtcNow; var observations = new Observation[] { new Observation(category, 0.9, new SKRect(image.Width / 5, image.Height / 4, image.Width / 3, image.Height / 2)), new Observation(category, 0.9, new SKRect(image.Width / 6, image.Height / 7, image.Width * 2 / 3, image.Height * 3 / 4)) }; var addedImageDao = DatabaseService.InsertOrUpdate(new ImageEntry(image, name, creationTime, null, observations)); var retrievedImageDao = DatabaseService.GetImage(addedImageDao.Id); Assert.AreEqual(addedImageDao, retrievedImageDao); }
/// <summary> /// Encode the content using the encoding scheme given /// </summary> /// <param name="content"></param> /// <param name="encoding"></param> /// <returns></returns> public virtual void EncodeInMetafile(MetaFile metafile, int posx, int posy, int modul, String content, Encoding encoding) { bool[][] matrix = calQrcode(encoding.GetBytes(content)); /*int PrintWidth = matrix.Length * qrCodeScale*modul + 1; * int PrintHeight = matrix.Length * qrCodeScale*modul + 1; * MetaObjectDraw metaobj = new MetaObjectDraw(); * metaobj.MetaType = MetaObjectType.Draw; * metaobj.Top = posy; * metaobj.Left = posx; * metaobj.Width = PrintWidth; * metaobj.Height = PrintHeight; * metaobj.DrawStyle = ShapeType.Rectangle; * metaobj.BrushStyle = (int)BrushType.Solid; * metaobj.PenStyle = (int)PenType.Clear; * metaobj.PenWidth = 0; * metaobj.PenColor = GraphicUtils.IntegerFromColor(qrCodeBackgroundColor); * metaobj.BrushColor = GraphicUtils.IntegerFromColor(qrCodeBackgroundColor); * metafile.Pages[metafile.CurrentPage].Objects.Add(metaobj);*/ int bwidth = qrCodeScale * modul; for (int i = 0; i < matrix.Length; i++) { for (int j = 0; j < matrix.Length; j++) { if (matrix[j][i]) { MetaObjectDraw metaobj = new MetaObjectDraw(); metaobj.MetaType = MetaObjectType.Draw; metaobj.Top = posy + i * bwidth; metaobj.Left = posx + j * bwidth; metaobj.Width = bwidth; metaobj.Height = bwidth; metaobj.DrawStyle = ShapeType.Rectangle; metaobj.BrushStyle = (int)BrushType.Solid; metaobj.PenStyle = (int)PenType.Solid; metaobj.PenWidth = 0; metaobj.PenColor = GraphicUtils.IntegerFromColor(qrCodeForegroundColor); metaobj.BrushColor = GraphicUtils.IntegerFromColor(qrCodeForegroundColor); metafile.Pages[metafile.CurrentPage].Objects.Add(metaobj); } } } }
public static Clock LoadClock() { if (!File.Exists(dir)) { return(DefaultClock()); } Dictionary <String, String> LoadDict = DOD.Load(dir); try { Clock ReturnClock; if (string.IsNullOrWhiteSpace(FontDir)) { FontDir = LoadDict["FONT"]; } if (!string.IsNullOrWhiteSpace(FontDir)) { ReturnClock = new Clock(BasicFont.LoadFromFile(FontDir), 2, 1); } else { ReturnClock = new Clock(2, 1); } ReturnClock.BG = GraphicUtils.ColorCharToConsoleColor(LoadDict["BG"][0]); ReturnClock.FG = GraphicUtils.ColorCharToConsoleColor(LoadDict["FG"][0]); ReturnClock.MilitaryTime = Boolean.Parse(LoadDict["MILITTIME"]); ReturnClock.ShowDate = Boolean.Parse(LoadDict["SHOWDATE"]); ReturnClock.ShowSeconds = Boolean.Parse(LoadDict["SHOWSECONDS"]); ReturnClock.HourAdjust = int.Parse(LoadDict["ADJUSTHOURS"]); Audio = Boolean.Parse(LoadDict["AUDIO"]); Voice = Boolean.Parse(LoadDict["VOICE"]); Collapsed = Boolean.Parse(LoadDict["COLLAPSED"]); return(ReturnClock); } catch (Exception) { Draw.CenterText("There was an error loading file " + dir.Split('\\')[dir.Split('\\').Length - 1], Console.WindowHeight / 2, ConsoleColor.Red, ConsoleColor.Black); RenderUtils.Pause(); Draw.ClearLine(Console.WindowHeight / 2); return(DefaultClock()); } }
private bool ClickFontName(ref string fontname) { bool aresult = false; using (FontDialog ndialog = new FontDialog()) { // Search for other properties Font nfont = CreateOriginalFont(); ndialog.Font = new Font(fontname, nfont.Size, nfont.Style); if (ndialog.ShowDialog() == DialogResult.OK) { fontname = ndialog.Font.Name; SetNewFont(fontname, (int)Math.Round(ndialog.Font.Size), GraphicUtils.IntegerFromFontStyle(ndialog.Font.Style)); aresult = true; } } return(aresult); }
public void TestRemoveImage() { var image = GraphicUtils.GetImageByDimensions(100, 100); var category = new CategoryManager().GetOrCreate(18, "Small Car"); const string name = "Image.jpg"; var creationTime = DateTime.UtcNow; var observations = new Observation[] { new Observation(category, 0.9, new SKRect(image.Width / 5, image.Height / 4, image.Width / 3, image.Height / 2)), new Observation(category, 0.9, new SKRect(image.Width / 6, image.Height / 7, image.Width * 2 / 3, image.Height * 3 / 4)) }; var imageDaoToDelete = DatabaseService.InsertOrUpdate(new ImageEntry(image, name, creationTime, null, observations)); DatabaseService.DeleteImage(imageDaoToDelete.Id); Assert.IsNull(DatabaseService.GetImage(imageDaoToDelete.Id)); Assert.IsEmpty(DatabaseUtils.GetAllObservations()); }
public async Task ResizeImageOrdinary() { var thumWidth = 150; var thumHeight = 120; var basePath = AppDomain.CurrentDomain.BaseDirectory; var inputPath = Path.Combine(basePath, "files", "butterfly.jpg"); var outputPath = Path.Combine(basePath, "files", "butterfly_tmb.jpg"); if (File.Exists(outputPath)) { File.Delete(outputPath); } await GraphicUtils.Resize(inputPath, outputPath, thumWidth, thumHeight, Extensions.GraphicUtils.ImageFormats.UnKnown); var image = Image.Load(outputPath); Assert.True(File.Exists(outputPath) && image.Width == thumWidth && image.Height == thumHeight); }