public static bool IsAnimatedGif(string filename) { Image?img = null; try { img = Image.FromFile(filename); if (img == null) { return(false); } if (img.RawFormat.Guid == ImageFormat.Gif.Guid) { var fd = new FrameDimension(img.FrameDimensionsList[0]); var fd_count = img.GetFrameCount(fd); if (fd_count > 1) { return(true); } else { return(false); } } return(false); } catch (Exception) { return(false); } finally { img?.Dispose(); } }
/// <summary> /// Whether or not the image has multiple time-based frames. /// </summary> public static bool CanAnimate(Image?image) { if (image == null) { return(false); } // See comment in the class header about locking the image ref. #pragma warning disable CA2002 lock (image) { #pragma warning restore CA2002 Guid[] dimensions = image.FrameDimensionsList; foreach (Guid guid in dimensions) { FrameDimension dimension = new FrameDimension(guid); if (dimension.Equals(FrameDimension.Time)) { return(image.GetFrameCount(FrameDimension.Time) > 1); } } } return(false); }
protected override FrameworkElement CreateNativeView() { RealNativeView = new Image(); return(new Border { Child = RealNativeView }); }
public ImageButtonRaw() { HorizontalContentAlignment = HorizontalAlignment.Left; Background = Brushes.Transparent; var panel = new StackPanel { Name = "BtnPanel", Orientation = Orientation.Horizontal, }; panel.Children.Add(m_image = new Image { Name = "BtnImage", Margin = new Thickness(0, 0, 10, 0), Source = (ImageSource)Resources["check_reject.png"], }); panel.Children.Add(m_text = new TextBlock { Name = "BtnLabel", VerticalAlignment = VerticalAlignment.Center, FontSize = 16, Text = "Label", }); Content = panel; }
public BindImageMemoryInfoKHR ( StructureType?sType = StructureType.BindImageMemoryInfo, void *pNext = null, Image?image = null, DeviceMemory?memory = null, ulong?memoryOffset = null ) : this() { if (sType is not null) { SType = sType.Value; } if (pNext is not null) { PNext = pNext; } if (image is not null) { Image = image.Value; } if (memory is not null) { Memory = memory.Value; } if (memoryOffset is not null) { MemoryOffset = memoryOffset.Value; } }
/// <summary> /// Adds or replaces an image in the folder of images, this removes any image on the Images folder that has the same name as newImageName /// </summary> /// <param name="newImageName"></param> /// <param name="newImage"></param> public void AddOrReplace(string newImageName, Image?newImage) { try { if (File.Exists(Path.Join(ImagesPath, "/" + newImageName + ".png"))) { File.Delete(Path.Join(ImagesPath, "/" + newImageName + ".png")); } Images.TryRemove(newImageName, out var aux); aux?.Dispose(); if (newImage == null) { return; } newImage.Save(Path.Join(ImagesPath, "/" + newImageName + ".png")); Images.GetOrAdd(newImageName, (Image)newImage.Clone()); newImage.Dispose(); } catch (Exception e) { var exception = new ChainingException(e.Message); exception.AddErrorToChain("While trying to replace image"); throw exception; } }
// Just forwards to Image.FromFile eating any non-critical exceptions that may result. private static Image?GetImageFromFile(string?imageFile, bool large, bool scaled = true) { Image?image = null; try { if (imageFile != null) { string?ext = Path.GetExtension(imageFile); if (ext != null && string.Equals(ext, ".ico", StringComparison.OrdinalIgnoreCase)) { //ico files support both large and small, so we respect the large flag here. using (FileStream reader = File.OpenRead(imageFile !)) { image = GetIconFromStream(reader, large, scaled); } } else if (!large) { //we only read small from non-ico files. image = Image.FromFile(imageFile !); Bitmap?b = image as Bitmap; if (DpiHelper.IsScalingRequired && scaled) { DpiHelper.ScaleBitmapLogicalToDevice(ref b); } } } } catch (Exception e) when(!ClientUtils.IsCriticalException(e)) { } return(image); }
private void LoadFrame(int index) { if (index >= 0 && index < _images.Length) { _currentImage = Image.Load(_images[_currentIndex].FullName); } }
public DedicatedAllocationMemoryAllocateInfoNV ( StructureType?sType = StructureType.DedicatedAllocationMemoryAllocateInfoNV, void *pNext = null, Image?image = null, Buffer?buffer = null ) : this() { if (sType is not null) { SType = sType.Value; } if (pNext is not null) { PNext = pNext; } if (image is not null) { Image = image.Value; } if (buffer is not null) { Buffer = buffer.Value; } }
private static Image?GetBitmapFromResource(Type t, string?bitmapname, bool large, bool scaled) { if (bitmapname == null) { return(null); } Image?img = null; // Load the image from the manifest resources. Stream?stream = BitmapSelector.GetResourceStream(t, bitmapname); if (stream != null) { Bitmap?b = new Bitmap(stream); img = b; MakeBackgroundAlphaZero(b); if (large) { img = new Bitmap(b, s_largeSize.Width, s_largeSize.Height); } if (DpiHelper.IsScalingRequired && scaled) { b = (Bitmap)img; DpiHelper.ScaleBitmapLogicalToDevice(ref b); img = b; } } return(img); }
public static Image?GetPictureFromIPictureDisp(object picture) { if (picture is null) { return(null); } int hPal = default; IPictureDisp pict = (IPictureDisp)picture; PICTYPE type = (PICTYPE)pict.Type; if (type == PICTYPE.BITMAP) { try { hPal = pict.hPal; } catch (COMException) { } } Image?image = GetPictureFromParams(pict.Handle, type, hPal, pict.Width, pict.Height); GC.KeepAlive(pict); return(image); }
// Important Events private void ClickView(object sender, EventArgs e) { var pb = WinFormsUtil.GetUnderlyingControl <PictureBox>(sender); int index = Array.IndexOf(PKXBOXES, pb); if (index >= RES_MAX) { System.Media.SystemSounds.Exclamation.Play(); return; } index += SCR_Box.Value * RES_MIN; if (index >= Results.Count) { System.Media.SystemSounds.Exclamation.Play(); return; } var enc = Results[index]; var pk = enc.ConvertToPKM(SAV); pk.RefreshChecksum(); PKME_Tabs.PopulateFields(pk, false); slotSelected = index; slotColor = SpriteUtil.Spriter.View; FillPKXBoxes(SCR_Box.Value); }
public FactoryCheckItem(string name, Guid id, string description, Image?image) { Name = name; ID = id; Description = description; Image = image; }
public AnalogyNotification(Guid primaryFactoryId, string title, string message, AnalogyLogLevel level, Image?smallImage, int durationSeconds, Action?actionOnClick) : this(primaryFactoryId, title, message) { Level = level; SmallImage = smallImage; DurationSeconds = durationSeconds; ActionOnClick = actionOnClick; }
private void Awake() { var time = IPA.Utilities.Utils.CanUseDateTimeNowSafely ? DateTime.Now : DateTime.UtcNow; _jokeTime = (time.Day == 18 && time.Month == 6) || (time.Day == 1 && time.Month == 4); gameObject.transform.position = Position; gameObject.transform.eulerAngles = Rotation; gameObject.transform.localScale = Scale; _canvas = gameObject.AddComponent<Canvas>(); _canvas.renderMode = RenderMode.WorldSpace; _canvas.enabled = false; var rectTransform = _canvas.transform as RectTransform; rectTransform.sizeDelta = CanvasSize; _authorNameText = BeatSaberMarkupLanguage.BeatSaberUI.CreateText(_canvas.transform as RectTransform, AuthorNameText, AuthorNamePosition); rectTransform = _authorNameText.transform as RectTransform; rectTransform.SetParent(_canvas.transform, false); rectTransform.anchoredPosition = AuthorNamePosition; rectTransform.sizeDelta = HeaderSize; _authorNameText.text = AuthorNameText; _authorNameText.fontSize = AuthorNameFontSize; var pluginText = _jokeTime ? "SongCore Cleaner" : PluginNameText; _pluginNameText = BeatSaberMarkupLanguage.BeatSaberUI.CreateText(_canvas.transform as RectTransform, pluginText, PluginNamePosition); rectTransform = _pluginNameText.transform as RectTransform; rectTransform.SetParent(_canvas.transform, false); rectTransform.sizeDelta = HeaderSize; rectTransform.anchoredPosition = PluginNamePosition; _pluginNameText.text = pluginText; _pluginNameText.fontSize = PluginNameFontSize; _headerText = BeatSaberMarkupLanguage.BeatSaberUI.CreateText(_canvas.transform as RectTransform, HeaderText, HeaderPosition); rectTransform = _headerText.transform as RectTransform; rectTransform.SetParent(_canvas.transform, false); rectTransform.anchoredPosition = HeaderPosition; rectTransform.sizeDelta = HeaderSize; _headerText.text = HeaderText; _headerText.fontSize = HeaderFontSize; _loadingBackg = new GameObject("Background").AddComponent<Image>(); rectTransform = _loadingBackg.transform as RectTransform; rectTransform.SetParent(_canvas.transform, false); rectTransform.sizeDelta = LoadingBarSize; _loadingBackg.color = BackgroundColor; _loadingBar = new GameObject("Loading Bar").AddComponent<Image>(); rectTransform = _loadingBar.transform as RectTransform; rectTransform.SetParent(_canvas.transform, false); rectTransform.sizeDelta = LoadingBarSize; var tex = Texture2D.whiteTexture; var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f, 100, 1); _loadingBar.sprite = sprite; _loadingBar.type = Image.Type.Filled; _loadingBar.fillMethod = Image.FillMethod.Horizontal; _loadingBar.color = new Color(1, 1, 1, 0.5f); DontDestroyOnLoad(gameObject); }
public void Play() { _isPlaying = true; Passed = false; _hasInformedCriticalZone = false; _cactus = Image.FromFile(_random.Next(0, 100) > 50 ? "CSA_GAME/Resources/Cactus/_cactus1.png" : "CSA_GAME/Resources/Cactus/_cactus2.png"); }
public Item(int id, string name, string description, Image?image, int price) { this.Id = id; this.Name = name; this.Description = description; this.Image = image; this.Price = price; }
public override void Start() { base.Start(); _random = new Random(); _cactus = Image.FromFile(_random.Next(0, 100) > 50 ? "CSA_GAME/Resources/Cactus/_cactus1.png" : "CSA_GAME/Resources/Cactus/_cactus2.png"); Transform.Position.X = Engine.Game.Instance.Scene.Width + Offset; }
public MenuButton(string text, Action?action = null, Image?image = null) : base(text, image) { if (action != null) { Click += delegate { action(); }; } }
public Boss(string Name, Image?image, int health, int Level, int Damage) { this.Name = Name; this.Image = image; this.Health = health; this.Level = Level; this.Damage = Damage; }
public AnalogyToolTip(string title, string content, string footer, Image?smallImage, Image?largeImage) { Title = title; Content = content; Footer = footer; SmallImage = smallImage; LargeImage = largeImage; }
// Constructors. public TextureBrush(Image?image) { if (image == null) { throw new ArgumentNullException("image"); } Image = image; }
public BlitImageInfo2KHR ( StructureType?sType = StructureType.BlitImageInfo2Khr, void *pNext = null, Image?srcImage = null, ImageLayout?srcImageLayout = null, Image?dstImage = null, ImageLayout?dstImageLayout = null, uint?regionCount = null, ImageBlit2KHR *pRegions = null, Filter?filter = null ) : this() { if (sType is not null) { SType = sType.Value; } if (pNext is not null) { PNext = pNext; } if (srcImage is not null) { SrcImage = srcImage.Value; } if (srcImageLayout is not null) { SrcImageLayout = srcImageLayout.Value; } if (dstImage is not null) { DstImage = dstImage.Value; } if (dstImageLayout is not null) { DstImageLayout = dstImageLayout.Value; } if (regionCount is not null) { RegionCount = regionCount.Value; } if (pRegions is not null) { PRegions = pRegions; } if (filter is not null) { Filter = filter.Value; } }
/// <summary> /// Advances the frame in the specified image. The new frame is drawn the next time the image is rendered. /// </summary> public static void UpdateFrames(Image?image) { if (image == null || s_imageInfoList == null) { return; } if (t_threadWriterLockWaitCount > 0) { // Cannot acquire reader lock - frame update will be missed. return; } // If the current thread already has the writer lock, no reader lock is acquired. Instead, the lock count on // the writer lock is incremented. It already has a reader lock, the locks ref count will be incremented // w/o placing the request at the end of the reader queue. s_rwImgListLock.AcquireReaderLock(Timeout.Infinite); try { bool foundDirty = false; bool foundImage = false; foreach (ImageInfo imageInfo in s_imageInfoList) { if (imageInfo.Image == image) { if (imageInfo.FrameDirty) { // See comment in the class header about locking the image ref. lock (imageInfo.Image) { imageInfo.UpdateFrame(); } } foundImage = true; } else if (imageInfo.FrameDirty) { foundDirty = true; } if (foundDirty && foundImage) { break; } } s_anyFrameDirty = foundDirty; } finally { s_rwImgListLock.ReleaseReaderLock(); } }
public TextureBrush(Image?image, RectangleF dstRect) { if (image == null) { throw new ArgumentNullException("image"); } Image = image; this.dstRect = dstRect; }
public MenuButton(string text, Action?action = null, Image?image = null) : base(text, image) { ImageScaling = ToolStripItemImageScaling.None; if (action != null) { Click += delegate { action(); }; } }
public SplitButton(string text, Action?action = null, Image?image = null) : base(text, image) { AutoToolTip = false; if (action != null) { ButtonClick += delegate { action(); }; } }
/// <summary> /// Allows a plugin to register a new commit template. /// </summary> /// <param name="templateName">The name of the template.</param> /// <param name="templateText">The body of the template.</param> public void Register(string templateName, Func <string> templateText, Image?icon) { lock (RegisteredTemplatesStorage) { if (RegisteredTemplatesStorage.All(item => item.Name != templateName)) { RegisteredTemplatesStorage.Add(new RegisteredCommitTemplateItem(templateName, templateText, icon)); } } }
/// <summary> /// This class represents all the information to render the ToolStrip /// </summary> public ToolStripItemImageRenderEventArgs( Graphics g, ToolStripItem item, Image?image, Rectangle imageRectangle) : base(g, item) { Image = image; ImageRectangle = imageRectangle; }
// ReSharper disable Unity.InefficientPropertyAccess internal LevelDetailViewController() { _standardLevelDetailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().LastOrDefault(); if (_standardLevelDetailViewController == null) { return; } var levelDetail = _standardLevelDetailViewController.transform.Find("LevelDetail"); if (levelDetail == null) { _standardLevelDetailViewController = null; return; } BSMLParser.instance.Parse(Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "BeatSaberCinema.VideoMenu.Views.level-detail.bsml"), levelDetail.gameObject, this); SetActive(false); _buttonUnderline = _button.transform.Find("Underline").gameObject.GetComponent <Image>(); //Clone background from level difficulty selection var beatmapDifficulty = levelDetail.Find("BeatmapDifficulty"); var beatmapCharacteristic = levelDetail.Find("BeatmapCharacteristic"); var actionButtons = levelDetail.Find("ActionButtons"); var levelDetailBackground = beatmapDifficulty.Find("BG"); if (beatmapDifficulty == null || beatmapCharacteristic == null || actionButtons == null || levelDetailBackground == null) { _standardLevelDetailViewController = null; return; } var characteristicTransform = beatmapCharacteristic.GetComponent <RectTransform>(); var difficultyTransform = beatmapDifficulty.GetComponent <RectTransform>(); var actionButtonTransform = actionButtons.GetComponent <RectTransform>(); //The difference between characteristic and difficulty transforms. Using this would make it equal size to those var offsetMinYDifference = difficultyTransform.offsetMin.y + (difficultyTransform.offsetMin.y - characteristicTransform.offsetMin.y); //The maximum it can be without overlapping with the action buttons var offsetMinYMax = actionButtonTransform.offsetMin.y + actionButtonTransform.sizeDelta.y; //We take whichever is larger to make best use of the available space var offsetMinY = Math.Max(offsetMinYDifference, offsetMinYMax); var offsetMin = new Vector2(difficultyTransform.offsetMin.x, offsetMinY); var offsetMax = new Vector2(difficultyTransform.offsetMax.x, difficultyTransform.offsetMax.y + (difficultyTransform.offsetMax.y - characteristicTransform.offsetMax.y)); var rectTransform = _root.GetComponent <RectTransform>(); rectTransform.offsetMin = offsetMin; rectTransform.offsetMax = offsetMax; Object.Instantiate(levelDetailBackground, _root.transform); }