public void SelectImage(ImageHolder ih) { if(imgHolderSel!=null) { imgHolderSel.isSelected = false; imgHolderSel.Update(); } imgHolderSel = ih; ih.isSelected = true; ih.Update(); if (imgHolderSel.isAssetImg) { cbDelete.Background = new SolidColorBrush(Color.FromArgb(255, 224, 224, 224)); lbDelete.Foreground = new SolidColorBrush(Colors.Silver); cbSet.Background = new SolidColorBrush(Color.FromArgb(255, 224, 224, 224)); lbSet.Foreground = new SolidColorBrush(Colors.Silver); } else { cbDelete.Background = new SolidColorBrush(Colors.Silver); lbDelete.Foreground = new SolidColorBrush(Colors.Black); cbSet.Background = new SolidColorBrush(Colors.Silver); lbSet.Foreground = new SolidColorBrush(Colors.Black); } // Now update the big image iMain.Source = ih.i.DataImage; }
public static void Get(string id, string url, Action<BitmapImage> readyAction) { if (string.IsNullOrEmpty(id)) return; if (string.IsNullOrEmpty(url)) return; string localFile = Path.Combine(Global.BasePath, "cache", id); //state checking if (!images.ContainsKey(id)) { images[id] = new ImageHolder { Id = id, State = File.Exists(localFile) ? EnumImageState.Cached : EnumImageState.New }; if (readyAction != null) images[id].ReadyActions.Add(readyAction); } var img = images[id]; switch (img.State) { case EnumImageState.New: Task.Run(() => { try { img.State = EnumImageState.Downloading; new WebClient().DownloadFile(url, localFile); img.Data = File.ReadAllBytes(localFile); img.Fire(); img.State = EnumImageState.Cached; } catch (Exception e) { Logger.Error(e); } }); break; case EnumImageState.Downloading: if (!img.ReadyActions.Contains(readyAction)) img.ReadyActions.Add(readyAction); break; case EnumImageState.Cached: try { if (img.Data == null) img.Data = File.ReadAllBytes(localFile); if (img.Data.Length == 0) return; call(readyAction, getBitmap(img.Data)); } catch (Exception e) { Logger.Error(e); } break; default: break; } }
public void Awake() { if (TxtDaysOccupied == null) { GameObject UImenu = GameObject.FindGameObjectWithTag("UI"); IM = UImenu.transform.GetComponent("ImageHolder") as ImageHolder; BedroomMenu = UImenu.transform.FindChild("Popups").transform.FindChild("BedroomMenu").gameObject; TxtTitle = BedroomMenu.transform.FindChild("txtTitle").GetComponent<Text>(); TxtDaysOccupied = BedroomMenu.transform.FindChild("txtDaysOccupied").GetComponent<Text>(); TxtCondition = BedroomMenu.transform.FindChild("txtCondition").GetComponent<Text>(); btnRepair = BedroomMenu.transform.FindChild("btn_Repair").GetComponent<Button>(); btnUpgrade2 = BedroomMenu.transform.FindChild("btn_Upgrade2").GetComponent<Button>(); btnUpgrade3 = BedroomMenu.transform.FindChild("btn_Upgrade3").GetComponent<Button>(); btnUpgrade4 = BedroomMenu.transform.FindChild("btn_Upgrade4").GetComponent<Button>(); btnUpgrade5 = BedroomMenu.transform.FindChild("btn_Upgrade5").GetComponent<Button>(); } BedroomBehaviour.AddToRoomList(this); refurbCTR = GameObject.Find("RefurbishmentCTR").GetComponent<Refurbishment>(); }
public void SetUp() { var imageSavers = new List <IImageSaver> { new PngSaver(), new JpgSaver() }; var fileReaders = new List <IFileAllLinesReader> { new TxtReader(), new DocReader() }; var fileReader = new FileReader(new FileReaderProvider(fileReaders)); var imageHolder = new ImageHolder(new ImageSaverProvider(imageSavers)); var imageSettings = new ImageSettings(); var wordFrequency = new WordFrequency(new GrammemeChecker()); var painter = new TagCloudPainter(imageHolder, imageSettings); var algorithmGenerator = new Func <Point, ILayoutAlgorithm>(x => new SpiralAlgorithm(x)); var layoutGenerator = new Func <ILayoutAlgorithm, TagCloudLayouter>(x => new TagCloudLayouter(x)); tagCloudCommand = new TagCloudCommand( painter, wordFrequency, imageSettings, imageSettings, algorithmGenerator, layoutGenerator, fileReader); saveCommand = new SaveCommand(imageHolder); addColorCommand = new AddColorCommand(imageSettings); setFontCommand = new SetFontCommand(imageSettings); setImageSizeCommand = new SetImageSizeCommand(imageSettings); }
public override void GetView(int position, ViewHolder holder, Graphics g) { Message obj = GetItem(position); holder.UserData = obj; Rectangle rec = Rectangle.Empty; Contact user = null; if (obj.IsSend) { user = obj.Mime; } else { user = obj.Remote; } if (user != null && user.HeadImage != null) { defaultImage = user.HeadImage; } if (obj.IsSend) { rec = new Rectangle(holder.bounds.Width - 65, holder.bounds.Y + 10, 40, 40); } else { rec = new Rectangle(20, holder.bounds.Y + 10, 40, 40); } g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawImage(defaultImage, rec, new Rectangle(0, 0, defaultImage.Width, defaultImage.Height), GraphicsUnit.Pixel); switch (obj.MsgType) { case 1: TextHolder.DrawItem(obj, holder, g); break; case 34: VoiceHolder.DrawItem(obj, holder, g, owner); //TextHolder.DrawItem("【语音消息】MsgType=" + obj.MsgType, holder, g); break; case 3: ImageHolder.DrawItem(obj, holder, g); //TextHolder.DrawItem("【图片消息】MsgType=" + obj.MsgType, holder, g); break; case 47: ClownHolder.DrawItem(obj, holder, g); //TextHolder.DrawItem("【动画表情】MsgType=" + obj.MsgType, holder, g, obj.IsSend); break; case 49: TextHolder.DrawItem("【红包消息/文件消息/分享连接】MsgType=" + obj.MsgType, holder, g); break; case 42: TextHolder.DrawItem("【名片消息】MsgType=" + obj.MsgType, holder, g); break; case 43: TextHolder.DrawItem("【小视频消息】MsgType=" + obj.MsgType, holder, g); break; case 37: TextHolder.DrawItem("【添加好友 通知】MsgType=" + obj.MsgType, holder, g); break; case 8558: TextHolder.DrawItem("【位置信息】MsgType=" + obj.MsgType, holder, g); break; case 9000: TextHolder.DrawItem("【文件消息】MsgType=" + obj.MsgType, holder, g); break; case 10000: TextHolder.DrawItem("【系统消息】MsgType=" + obj.MsgType, holder, g); break; default: TextHolder.DrawItem("【未知消息类型】MsgType=" + obj.MsgType, holder, g); break; } }
/// <summary> /// Creates an PNG image for given Subtitle caption /// </summary> /// <param name="caption">Subtitle caption</param> /// <param name="style">Subtitle style</param> /// <param name="number">Caption number</param> /// <param name="videoWidth">Video width</param> /// <param name="videoHeight">Video height</param> /// <param name="baseFName">File base name</param> /// <returns>Generated PNG image</returns> public static ImageHolder CreateImage(SubCaption caption, SubtitleStyle style, int number, int videoWidth, int videoHeight, string baseFName) { _boldStyle = false; _italicStyle = false; _underlineStyle = false; _strikeStyle = false; var result = new ImageHolder(); if (string.IsNullOrEmpty(baseFName)) { return(new ImageHolder()); } var basePath = Path.GetDirectoryName(baseFName); var baseName = Path.GetFileNameWithoutExtension(baseFName); if (string.IsNullOrEmpty(basePath) || string.IsNullOrEmpty(baseName)) { return(new ImageHolder()); } result.FileName = $"{Path.Combine(basePath, baseName)}_{number:00000}.png"; var imgSize = new SizeF(); var styleFontStyle = FontStyle.Regular; if (style.Bold) { styleFontStyle = styleFontStyle | FontStyle.Bold; } if (style.Italic) { styleFontStyle = styleFontStyle | FontStyle.Italic; } var styleFont = new Font(style.FontName, style.FontSize, styleFontStyle, GraphicsUnit.Point); var stringFormat = new StringFormat(); var lineSizes = new List <SizeF>(); var rawText = Regex.Replace(caption.Text, "</*?(?:i|b)>", "", RegexOptions.Singleline | RegexOptions.Multiline); var rawTextLines = rawText.Split(new[] { Environment.NewLine }, StringSplitOptions.None); foreach (var rawTextLine in rawTextLines) { using (var rawLinePath = new GraphicsPath()) { rawLinePath.AddString(rawTextLine, styleFont.FontFamily, (int)styleFontStyle, styleFont.SizeInPoints, new PointF(), stringFormat); lineSizes.Add(rawLinePath.GetBounds().Size); } } var textLines = caption.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var lastLineBreak = 0f; foreach (var lineSize in lineSizes) { imgSize.Height += lineSize.Height; lastLineBreak = lineSize.Height / 3; imgSize.Height += lastLineBreak; if (lineSize.Width > imgSize.Width) { imgSize.Width = lineSize.Width; } } imgSize.Height -= lastLineBreak; if (imgSize.IsEmpty) { return(new ImageHolder()); } stringFormat.SetMeasurableCharacterRanges(new[] { new CharacterRange(0, 1) }); RectangleF whiteSpace; using (Image img = new Bitmap((int)imgSize.Width, (int)imgSize.Height, PixelFormat.Format32bppArgb)) { using (var g = Graphics.FromImage(img)) { var origin = new RectangleF(new PointF(0f, 0f), imgSize); var regions2 = g.MeasureCharacterRanges(" .", styleFont, origin, stringFormat); if (!regions2.Any()) { return(new ImageHolder()); } whiteSpace = regions2[0].GetBounds(g); } } var wordpath = new GraphicsPath(); var wordPathShadow = new GraphicsPath(); var shadowOffset = style.Shadow; var wStart = new RectangleF { Y = 0, X = 0 }; var wStartShadow = wStart; wStartShadow.Offset(shadowOffset, shadowOffset); for (var i = 0; i < textLines.Length; i++) { var textLine = textLines[i]; var lineSize = lineSizes[i]; wStart.Offset(imgSize.Width / 2 - lineSize.Width / 2, 0); wStartShadow.Offset(imgSize.Width / 2 - lineSize.Width / 2, 0); var words = textLine.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); foreach (var word in words) { using (GraphicsPath singleWord = new GraphicsPath(), singleWordShadow = new GraphicsPath()) { string lWord; var fontStyle = GetStyleFont(word, out lWord, styleFontStyle); if (string.IsNullOrEmpty(lWord)) { continue; } singleWord.AddString(lWord, styleFont.FontFamily, (int)fontStyle, styleFont.SizeInPoints, wStart.Location, stringFormat); singleWordShadow.AddString(lWord, styleFont.FontFamily, (int)fontStyle, styleFont.SizeInPoints, wStartShadow.Location, stringFormat); wordpath.AddPath(singleWord, false); wordPathShadow.AddPath(singleWordShadow, false); wStart.Offset(singleWord.GetBounds().Size.Width + whiteSpace.Size.Width, 0); wStartShadow.Offset(singleWordShadow.GetBounds().Size.Width + whiteSpace.Size.Width, 0); } } wStart.X = 0; wStart.Offset(0, lineSize.Height + lineSize.Height / 3); wStartShadow.X = shadowOffset; wStartShadow.Offset(0, lineSize.Height + lineSize.Height / 3); } imgSize.Width = wordPathShadow.GetBounds().Right; imgSize.Height = wordPathShadow.GetBounds().Bottom; using (Image img = new Bitmap((int)imgSize.Width + style.MarginL + style.MarginR, (int)imgSize.Height + style.MarginV * 2, PixelFormat.Format32bppArgb)) { using (var g = Graphics.FromImage(img)) { g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.HighQuality; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.InterpolationMode = InterpolationMode.High; Brush primBrush = new SolidBrush(style.PrimaryColor); Brush shadowBrush = new SolidBrush(Color.FromArgb(64, style.BackColor)); var outPen = new Pen(style.OutlineColor) { Alignment = PenAlignment.Outset }; if (style.BorderStyle == 1) { outPen.Width = style.Outline == 0 && style.Shadow > 0 ? 1 : style.Outline; style.Outline = (int)outPen.Width; } g.FillRectangle(Brushes.Transparent, 0, 0, img.Width, img.Height); // draw shadow if (style.BorderStyle == 1 && style.Shadow > 0) { g.FillPath(shadowBrush, wordPathShadow); } g.FillPath(primBrush, wordpath); // draw outline if (style.BorderStyle == 1 && style.Outline > 0) { g.DrawPath(outPen, wordpath); } } img.Save(result.FileName, ImageFormat.Png); result.FileName = Path.GetFileName(result.FileName); result.Height = img.Height; result.Width = img.Width; } return(result); }
/** * SciGraph Button Eventhandler. * Activates/Deactivates ImageHolder. */ public void ImageHolderHandler() { ImageHolder.SetActive(!ImageHolder.activeSelf); }
/// <summary> /// Get the ImageHolder object with the width and height of the image and the boxes /// </summary> /// <param name="boxes">boxes tensor</param> /// <param name="scores">scores tensor</param> /// <param name="classes">classes tensor</param> /// <param name="inputFile">path of source file</param> /// <param name="minScore">min score 0-1</param> /// <returns>Returns a ImageHolder object with all object data</returns> private static ImageHolder GetBoxes(float[,,] boxes, float[,] scores, float[,] classes, string inputFile, double minScore) { //var boxesList = new List<ImageHolder>(); var boxesList = new ImageHolder(); boxesList.Dimensions = ImageMeta.GetJpegDimensions(inputFile); var x = boxes.GetLength(0); var y = boxes.GetLength(1); var z = boxes.GetLength(2); float ymin = 0, xmin = 0, ymax = 0, xmax = 0; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (scores[i, j] < minScore) { continue; // < } int value = Convert.ToInt32(classes[i, j]); Console.WriteLine(value); for (int k = 0; k < z; k++) { var box = boxes[i, j, k]; switch (k) { case 0: ymin = box; break; case 1: xmin = box; break; case 2: ymax = box; break; case 3: xmax = box; break; } } CatalogItem catalogItem = _catalog.FirstOrDefault(item => item.Id == value); //Console.WriteLine(xmax); //Console.WriteLine(ymax); //Console.WriteLine(boxesList.Dimensions.Width); //Console.WriteLine(boxesList.Dimensions.Height); if (!string.IsNullOrEmpty(catalogItem?.DisplayName)) { // Calculate the absolute width and height of a object float left; float right; float top; float bottom; (left, right, top, bottom) = (xmin * boxesList.Dimensions.Width, xmax *boxesList.Dimensions.Width, ymin *boxesList.Dimensions.Height, ymax *boxesList.Dimensions.Height); var boxesItem = new ImageMetaData { Keyword = catalogItem.DisplayName, Class = catalogItem.Id, Left = left, Right = right, Bottom = bottom, Top = top, Height = bottom - top, Width = bottom - top, Score = scores[i, j] }; boxesList.Data.Add(boxesItem); boxesList.KeywordList.Add(catalogItem.DisplayName); } } } return(boxesList); }
public void ChangeLanguage(bool onStart) { if (!onStart) { foreach (object p in Enum.GetValues(typeof(Game))) { GameProperty gameProperty = RConfig.Instance.getGameProperty((Game)p); gameProperty.ListLoader.IsValid = false; gameProperty.ListLoader.Items[ListFileType.CRITICAL].Clear(); gameProperty.ListLoader.Items[ListFileType.NORMAL].Clear(); } } Text = LanguageHolder.Instance()[WordEnum.TITLE]; _infoStart.Text = LanguageHolder.Instance()[WordEnum.START_INFO]; _selectGameLabel.Text = LanguageHolder.Instance()[WordEnum.GAMES]; _lastNews.Text = LanguageHolder.Instance()[WordEnum.LAST_NEWS]; _startButton.Info = ImageHolder.Instance()[PictureName.START]; _closeBtn.Info = ImageHolder.Instance()[PictureName.CLOSE]; _fullCheck.Info = ImageHolder.Instance()[PictureName.FULLCHECK]; _settingsButton.Info = ImageHolder.Instance()[PictureName.SETTINGS]; _minimizedButton.Info = ImageHolder.Instance()[PictureName.MINI]; var Y = _homePage.Location.Y; var sepDiff = _separator1.Width / 2; _homePage.Text = LanguageHolder.Instance()[WordEnum.HOMEPAGE]; _separator1.Location = new Point(_homePage.Width + _homePage.Location.X + DIFF - sepDiff, Y); _faqLabel.Location = new Point(sepDiff + _separator1.Location.X + DIFF, Y); _faqLabel.Text = LanguageHolder.Instance()[WordEnum.FAQ]; _separator2.Location = new Point(_faqLabel.Width + _faqLabel.Location.X + DIFF - sepDiff, Y); _forumLabel.Location = new Point(sepDiff + _separator2.Location.X + DIFF, Y); _forumLabel.Text = LanguageHolder.Instance()[WordEnum.FORUM]; _separator3.Location = new Point(_forumLabel.Width + _forumLabel.Location.X + DIFF - sepDiff, Y); _joinNowLabel.Location = new Point(sepDiff + _separator3.Location.X + DIFF, Y); _joinNowLabel.Text = LanguageHolder.Instance()[WordEnum.JOIN_NOW]; _separator4.Location = new Point(_joinNowLabel.Width + _joinNowLabel.Location.X + DIFF - sepDiff, Y); _rulesLabel.Location = new Point(sepDiff + _separator4.Location.X + DIFF, Y); _rulesLabel.Text = LanguageHolder.Instance()[WordEnum.RULES]; switch (LanguageHolder.Instance().Language.ShortName) { case "en": _homePage.Tag = "http://aionwars.com"; _faqLabel.Tag = "http://aionwars.com/how_connect_to_server_aionwars.html"; _forumLabel.Tag = "http://forum.aionwars.com/forumdisplay.php?f=16"; _joinNowLabel.Tag = "http://aionwars.com/autoregen.html"; _rulesLabel.Tag = "http://aionwars.com/rules_of_aion_wars.html"; break; default: _homePage.Tag = "http://awars.net"; _faqLabel.Tag = "http://awars.net/bystryy_start.html"; _forumLabel.Tag = "http://forum.aionwars.com"; _joinNowLabel.Tag = "http://awars.net/autoreg.html"; _rulesLabel.Tag = "http://awars.net/pravila_servera.html"; break; } SetVersionType(Version, VersionType); UpdateAllRSS(); }
public Form NewMainWindow(bool fTesting) { try { ImageHolder holder = new ImageHolder(); // TODO: may want to add following to xml at some point or put it in configuration Path using Cabhab.ico as name // We are putting the configuration files in the common app directory string sAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string sCabhabDirectory = Path.Combine(sAppData, Path.Combine("SIL", "Cabhab")); string sConfigPath = Path.Combine(sCabhabDirectory, "Configurations"); string sConfig = Path.Combine(sConfigPath, ConfigurationFile); ConfigurationFileFullPath = sConfig; string sConfigSettings = Path.Combine(sCabhabDirectory, "ConfigurationSettings"); if (!Directory.Exists(sConfigSettings)) { Directory.CreateDirectory(sConfigSettings); } Mediator.PropertyTable.UserSettingDirectory = sConfigSettings; //MessageBox.Show("Before LoadUi(). sConfig = " + sConfig); LoadUI(sConfig); //Argument("x")); //MessageBox.Show("Before getting icon file"); string sIconFile = Mediator.PropertyTable.GetStringProperty("CabhabAppIcon", null); //MessageBox.Show("Before changing icon: sIconFile = " + sIconFile); sIconFile = Path.Combine(sConfigPath, sIconFile); //MessageBox.Show("Before setting icon: sIconFile = " + sIconFile); Icon = new System.Drawing.Icon(sIconFile); if (!fTesting) { //m_mainSplitterContainer.Panel1Collapsed = true; GetToolAndStatusBars(); m_viewer = (HtmlViewer) Mediator.PropertyTable.GetValue("currentContentControlObject"); m_viewer.ChangeShowToolbar += new EventHandler(OnChangeShowToolbar); m_viewer.ChangeShowStatusBar += new EventHandler(OnChangeShowStatusBar); Language m_lang = m_viewer.m_lang; m_lang.ChangeLanguageName += new EventHandler(OnChangeLanguageName); string sLangName = (m_lang != null) ? sLangName = m_lang.Name : ""; Mediator.PropertyTable.SetProperty("DocumentName", sLangName); UpdateCaptionBar(); if (m_sAnswerFile != null && File.Exists(m_sAnswerFile)) { m_lang.LoadAnswerFile(m_sAnswerFile); m_lang.LanguageNameChanged(); } Show(); } return this; } catch(Exception e) { MessageBox.Show("Exception caught: message =" + e.Message); MessageBox.Show("Inner exception = " + e.InnerException); return this; } }
private void cbNew_MouseDown(object sender, MouseButtonEventArgs e) { try { Edit_CaptureImage capImg = new Edit_CaptureImage(); capImg.SetSize(); if (capImg.ShowDialog() == true) { // Store the image back // First, we should delete the existing image // Then we should add the new one // And finally assign it try { SEG.Domain.Model.Image img = ImageHelper.SaveImage(ControlCenter.Instance.segR, ControlCenter.Instance.imgPopResult); ImageHelper.FillImage(img); DiagnosticsHelper.SaveDiagnosticsImage(ControlCenter.Instance.segR, dm.Id, img.Id); ImageHolder ih = new ImageHolder(); ih.Width = 180; ih.Height = 180; ih.Initialize(img); sPanel.Children.Add(ih); imgHolders.Add(ih); SelectImage(ih); } catch (Exception ex) { StreamWriter sw = new StreamWriter("capture-error.txt"); sw.WriteLine(ex.ToString()); sw.Close(); } } } catch (Exception ex2) { StreamWriter sw = new StreamWriter("capture-error.txt"); sw.WriteLine(ex2.ToString()); sw.Close(); } }
public void Update(double estimatedWidth) { // First, clean all the Children of the panel sPanel.Children.Clear(); // Find the mechanical diagnostics dm = DiagnosticsHelper.GetMechanicalDiagnostics(ControlCenter.Instance.segR, ControlCenter.Instance.cAssetId); List<Diagnostics> electrical = DiagnosticsHelper.GetElectricalDiagnostics(ControlCenter.Instance.segR, ControlCenter.Instance.cAssetId); if (electrical.Count > 0) { hasElectrical = true; labName_S3_0.Foreground = new SolidColorBrush(Colors.White); } else { hasElectrical = false; labName_S3_0.Foreground = new SolidColorBrush(Colors.Gray); } // Obtain all the images for the Diagnostics List<SEG.Domain.Model.Image> imgs = DiagnosticsHelper.GetDiagnosticsImages(ControlCenter.Instance.segR, dm.Id); imgHolders = new List<ImageHolder>(); foreach(SEG.Domain.Model.Image img in imgs) { ImageHolder ih = new ImageHolder(); ih.Width = 180; ih.Height = 180; ih.Initialize(img); sPanel.Children.Add(ih); imgHolders.Add(ih); } imgHolderSel = null; cbDelete.Background = new SolidColorBrush(Color.FromArgb(255, 224, 224, 224)); lbDelete.Foreground = new SolidColorBrush(Colors.Silver); cbSet.Background = new SolidColorBrush(Color.FromArgb(255, 224, 224, 224)); lbSet.Foreground = new SolidColorBrush(Colors.Silver); if(imgHolders.Count>0) SelectImage(imgHolders[0]); else { iMain.Source = null; } }