예제 #1
0
        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();
            }
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 protected override FrameworkElement CreateNativeView()
 {
     RealNativeView = new Image();
     return(new Border {
         Child = RealNativeView
     });
 }
예제 #4
0
            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;
            }
예제 #5
0
        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;
            }
        }
예제 #6
0
        /// <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;
            }
        }
예제 #7
0
        // 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);
        }
예제 #8
0
 private void LoadFrame(int index)
 {
     if (index >= 0 && index < _images.Length)
     {
         _currentImage = Image.Load(_images[_currentIndex].FullName);
     }
 }
예제 #9
0
        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;
            }
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        // 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);
        }
예제 #13
0
 public FactoryCheckItem(string name, Guid id, string description, Image?image)
 {
     Name        = name;
     ID          = id;
     Description = description;
     Image       = image;
 }
예제 #14
0
 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;
 }
예제 #15
0
        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);
        }
예제 #16
0
 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");
 }
예제 #17
0
 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;
 }
예제 #18
0
 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;
 }
예제 #19
0
 public MenuButton(string text, Action?action = null, Image?image = null) :
     base(text, image)
 {
     if (action != null)
     {
         Click += delegate { action(); };
     }
 }
예제 #20
0
 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;
 }
예제 #22
0
 // 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;
            }
        }
예제 #24
0
        /// <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();
            }
        }
예제 #25
0
 public TextureBrush(Image?image, RectangleF dstRect)
 {
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     Image        = image;
     this.dstRect = dstRect;
 }
예제 #26
0
 public MenuButton(string text, Action?action = null, Image?image = null) :
     base(text, image)
 {
     ImageScaling = ToolStripItemImageScaling.None;
     if (action != null)
     {
         Click += delegate { action(); };
     }
 }
예제 #27
0
    public SplitButton(string text, Action?action = null, Image?image = null) :
        base(text, image)
    {
        AutoToolTip = false;

        if (action != null)
        {
            ButtonClick += delegate { action(); };
        }
    }
예제 #28
0
 /// <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);
        }