private void RenameShape(string newShapeName)
        {
            if (HasNameChanged(newShapeName))
            {
                return;
            }
            if (!IsValidName(newShapeName))
            {
                MessageBox.Show(Utils.ShapeUtil.IsShapeNameOverMaximumLength(newShapeName)
                                    ? CommonText.ErrorNameTooLong
                                    : CommonText.ErrorInvalidCharacter);
                textBox.Text = shapeName;
                EditStatus   = Status.Editing;
                return;
            }

            if (IsDuplicateName(newShapeName))
            {
                EditStatus = Status.Editing;
                return;
            }
            //Update image
            string newPath = ImagePath.Replace(@"\" + shapeName, @"\" + newShapeName);

            if (File.Exists(ImagePath))
            {
                File.Move(ImagePath, newPath);
                this.GetAddIn().ShapePresentation.RenameShape(shapeName, newShapeName);
            }
            ImagePath = newPath;

            ShapesLabUtils.SyncShapeRename(this.GetAddIn(), shapeName, newShapeName, parent.CurrentCategory);
            parent.RenameCustomShape(shapeName, newShapeName);
        }
        //maintains ratio creates images from 7 standard web sizes and saves
        public void CreateImagesForWeb()
        {
            foreach (var size in sizes)
            {
                using (Image <Rgba32> image = Image.Load(ImagePath))
                {
                    int Width  = (int)(image.Width * (size / (float)image.Width));
                    int Height = (int)(image.Height * (size / (float)image.Width));

                    var filename  = Path.GetFileName(ImagePath);
                    var extention = Path.GetExtension(filename);
                    var imagePath = ImagePath.Replace(filename, $"{ImageName}_W{Width}_H{Height}{extention}");

                    image.Mutate(x => x
                                 .Resize(Width, Height)
                                 );

                    image.Save(imagePath); // Automatic encoder selected based on extension.
                    Console.WriteLine($"File Saved As {Path.GetFileName(imagePath)}");
                }
            }
            using (var imageStream = new FileStream(ImagePath, FileMode.Open))
            {
                using (Image <Rgba32> image = Image.Load(imageStream))
                {
                }
            }
        }
Exemple #3
0
        private void cutZones()
        {
            CutImagePath = string.Empty;
            var newImagePath = ImagePath.Replace(".jpg", "__.jpg");
            var drawing      = new Leptonica.Drawing.PixDrawing();

            using (var pix = new Pix(ImagePath))
            {
                using (Boxa boxa = new Boxa(Zones.Count))
                {
                    foreach (var zone in Zones)
                    {
                        boxa.AddBox(new Box((int)zone.X, (int)zone.Y, (int)zone.ActualWidth, (int)zone.ActualHeight));
                    }

                    int height = (int)(Zones.Max(z => z.Y + z.Height) - Zones.Min(z => z.Y));
                    int width  = (int)(Zones.Max(z => z.X + z.Width) - Zones.Min(z => z.X));

                    using (var newPix = new Pix(pix.Width, pix.Height, pix.Depth))
                    {
                        using (var mask = new Pix(pix.Width, pix.Height, 1))
                        {
                            drawing.MaskBoxa(mask, mask, boxa, GraphicPixelSetting.SET_PIXELS);
                            if (!drawing.CombineMaskedGeneral(newPix, pix, mask, 0, 0))
                            {
                                throw new Exception("Could not mask");
                            }
                        }

                        newPix.Save(newImagePath, ImageFileFormat.JFIF_JPEG);
                        CutImagePath = newImagePath;
                    }
                }
            }
        }
        private bool IsDuplicateName(string newShapeName)
        {
            string newPath = ImagePath.Replace(shapeName, newShapeName);

            // if the new name has been used, the new name is not allowed
            if (File.Exists(newPath))
            {
                MessageBox.Show(CommonText.ErrorFileNameExist);
                return(true);
            }
            return(false);
        }
Exemple #5
0
        public Rss Generate()
        {
            var paths = System.IO.Directory.EnumerateFiles(FileDirectory);
            var files = new List <TagLib.File>();

            foreach (var path in paths)
            {
                var tFile = TagLib.File.Create(path);

                if (tFile.Tag.IsEmpty)
                {
                    continue;
                }

                files.Add(tFile);
            }

            var orderedFiles = files.OrderBy(f => f.Tag.Track);

            if (!orderedFiles.Any())
            {
                return(null);
            }

            var firstFile = orderedFiles.First();

            var rss = new Rss();

            rss.Channel = new Channel()
            {
                Title           = firstFile.Tag.Album,
                Description     = firstFile.Tag.Album,
                ItunesAuthor    = firstFile.Tag.JoinedPerformers,
                ItunesImageHref = new ItunesImage {
                    Href = ImagePath.Replace(FileDirectory, ServerPath)
                },
                Image = new Image {
                    Url = ImagePath.Replace(FileDirectory, ServerPath), Title = firstFile.Tag.Album
                },
            };
            rss.Channel.ItunesCategories.Add(new Category {
                Text = "Music"
            });
            rss.Channel.ItunesCategories[0].Categories.Add(new Category {
                Text = "Music Commentary"
            });

            var utcNow  = DateTime.UtcNow;
            var pubDate = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, 0, 0, 0, DateTimeKind.Utc);

            foreach (var tFile in orderedFiles)
            {
                var size = new FileInfo(tFile.FileAbstraction.Name).Length;

                var item = new Item()
                {
                    Title         = tFile.Tag.Title,
                    Description   = tFile.Tag.Title,
                    ItunesEpisode = tFile.Tag.Track.ToString(),
                    Guid          = new RssGuid {
                        Text = HashUtility.ComputeFileMd5Hash(tFile.FileAbstraction.Name)
                    },
                    PubDate        = pubDate,
                    ItunesDuration = tFile.Properties.Duration,
                    Author         = tFile.Tag.JoinedPerformers,
                    ItunesImage    = new ItunesImage {
                        Href = ImagePath.Replace(FileDirectory, ServerPath)
                    },
                    Enclosure = new Enclosure
                    {
                        Url    = tFile.FileAbstraction.Name.Replace(FileDirectory, ServerPath),
                        Length = size,
                        Type   = "audio/mpeg" //tFile.MimeType incorrect
                    }
                };

                rss.Channel.Items.Add(item);

                pubDate = pubDate.AddMinutes(1);
            }

            return(rss);
        }