Esempio n. 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MimeType.Length != 0)
            {
                hash ^= MimeType.GetHashCode();
            }
            if (ImageThumbnail.Length != 0)
            {
                hash ^= ImageThumbnail.GetHashCode();
            }
            if (ImageUri.Length != 0)
            {
                hash ^= ImageUri.GetHashCode();
            }
            if (SignedUri.Length != 0)
            {
                hash ^= SignedUri.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 2
0
    private int ProcessPhoto()
    {
        //生成小图目录
        //DirectoryInfo di_smallforder = Directory.CreateDirectory(smallfoldername);

        //取得大图目录信息
        DirectoryInfo imagesfile = new DirectoryInfo(bigfoldername);

        //取得大图目录所有JPG文件集合
        FileInfo[] fi = imagesfile.GetFiles("*.jpg");


        for (int i = 0; i < fi.Length; i++)
        {
            if (!File.Exists(smallfoldername + "/" + fi[i].Name))
            {
                //生成缩略图文件
                ImageThumbnail.MakeThumbnail(
                    bigfoldername + "/" + fi[i].Name,
                    smallfoldername + "/" + fi[i].Name,
                    150,
                    110,
                    "Cut"
                    );
            }
        }

        return(fi.Length);
    }
        // event handlers
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            // make sure name and unit are not empty string
            if (string.IsNullOrWhiteSpace(TextBoxName.Text))
            {
                FlyoutWarmingText.Text = "Name cannot be empty!";
                FlyoutWarming.ShowAt(TextBoxName);
                args.Cancel = true;
                return;
            }
            if (ComboBoxCategory.SelectedIndex == -1)
            {
                FlyoutWarmingText.Text = "Category cannot be empty!";
                FlyoutWarming.ShowAt(ComboBoxCategory);
                args.Cancel = true;
                return;
            }
            if (ComboBoxUnit.SelectedIndex == -1)
            {
                FlyoutWarmingText.Text = "Unit cannot be empty!";
                FlyoutWarming.ShowAt(ComboBoxUnit);
                args.Cancel = true;
                return;
            }

            // perform real update
            TextBoxName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            ComboBoxCategory.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateSource();
            ComboBoxUnit.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateSource();
            ImageThumbnail.GetBindingExpression(Image.SourceProperty).UpdateSource();
            this.ingredient.ThumbnailFilename = this.thumbnailFilename;
        }
Esempio n. 4
0
        public long Save(string path)
        {
            Directory.CreateDirectory(path);
            var  ConfigPath        = Path.Combine(path, Code + ".desktop");
            var  IconPath          = Path.Combine(path, Code + ".png");
            var  ThumnnailIconPath = Path.Combine(path, Code + "_small.png");
            char prefix;

            switch (position)
            {
            case Priority.Leftmost:
                prefix = (char)1;
                break;

            default:
            case Priority.Left:
                prefix = (char)2;
                break;

            case Priority.Right:
                prefix = 'Э';
                break;

            case Priority.Rightmost:
                prefix = 'Ю';
                break;

            case Priority.Back:
                prefix = 'Я';
                break;
            }
            File.WriteAllText(ConfigPath, string.Format(
                                  "[Desktop Entry]\n" +
                                  "Type=Application\n" +
                                  "Exec=/bin/chmenu {1:D3} {8}\n" +
                                  "Path=/var/lib/clover/profiles/0/FOLDER\n" +
                                  "Name={2}\n" +
                                  "Icon=/usr/share/games/nes/kachikachi/{0}/{0}.png\n\n" +
                                  "[X-CLOVER Game]\n" +
                                  "Code={0}\n" +
                                  "TestID=777\n" +
                                  "ID=0\n" +
                                  "Players={3}\n" +
                                  "Simultaneous={7}\n" +
                                  "ReleaseDate={4}\n" +
                                  "SaveCount=0\n" +
                                  "SortRawTitle={5}\n" +
                                  "SortRawPublisher={6}\n" +
                                  "Copyright=hakchi2 ©2017 Alexey 'Cluster' Avdyukhin\n",
                                  Code, ChildIndex, Name ?? Code, Players, ReleaseDate,
                                  prefix + (Name ?? Code).ToLower(), (Publisher ?? "").ToUpper(),
                                  Simultaneous, Initial)
                              );
            Image.Save(IconPath, ImageFormat.Png);
            ImageThumbnail.Save(ThumnnailIconPath, ImageFormat.Png);
            return(new FileInfo(ConfigPath).Length + new FileInfo(IconPath).Length + new FileInfo(ThumnnailIconPath).Length);
        }
Esempio n. 5
0
        public void ShouldCreateThumbnailImageFileWhenRequested()
        {
            const string thumbnailDirectory = "thunbmails";
            Directory.CreateDirectory(thumbnailDirectory);
            string fullPathToDirectory = Path.GetFullPath(thumbnailDirectory);
            ImageThumbnail imageThumbnail = new ImageThumbnail(fullPathToDirectory);
            imageThumbnail.CreateThumbnail("Tulips.jpg");

            Bitmap bitmap = new Bitmap(Path.Combine(thumbnailDirectory, "thumb-tulips.jpg"));
            Assert.AreEqual(ImageThumbnail.ThumbnailHeight, bitmap.Size.Height);
            Assert.AreEqual(ImageThumbnail.ThumbnailWidth, bitmap.Size.Width);
        }
        /// <summary>
        /// Take a photo from the WebCam. Make sure the camera is active.
        /// </summary>
        /// <returns>Image data with a Texture for thumbnail.</returns>
        public Task <ImageThumbnail> TakePhotoWithThumbnail()
        {
            if (!IsCameraActive)
            {
                throw new Exception("Can't take photo when camera is not ready.");
            }

            return(Task.Run(() =>
            {
                var completionSource = new TaskCompletionSource <ImageThumbnail>();

                AppDispatcher.Instance().Enqueue(() =>
                {
                    Debug.Log("Starting photo capture.");

#if UNITY_WSA
                    photoCapture.TakePhotoAsync((photoCaptureResult, frame) =>
                    {
                        Debug.Log("Photo capture done.");

                        var buffer = new List <byte>();
                        frame.CopyRawImageDataIntoBuffer(buffer);
                        var texture = new Texture2D(2, 2);
                        var imageData = buffer.ToArray();
                        texture.LoadImage(imageData);
                        var imageThumbnail = new ImageThumbnail
                        {
                            ImageData = imageData,
                            Texture = texture
                        };

                        completionSource.TrySetResult(imageThumbnail);
                    });
#else
                    var tex = new Texture2D(webCamTexture.width, webCamTexture.height);
                    tex.SetPixels(webCamTexture.GetPixels());
                    tex.Apply();
                    var data = tex.EncodeToPNG();
                    var imageThumbnail = new ImageThumbnail
                    {
                        ImageData = data,
                        Texture = tex
                    };

                    completionSource.TrySetResult(imageThumbnail);
#endif
                });

                return completionSource.Task;
            }));
        }
Esempio n. 7
0
        public void ShouldCreateThumbnailImageFileWhenRequested()
        {
            const string thumbnailDirectory = "thunbmails";

            Directory.CreateDirectory(thumbnailDirectory);
            string         fullPathToDirectory = Path.GetFullPath(thumbnailDirectory);
            ImageThumbnail imageThumbnail      = new ImageThumbnail(fullPathToDirectory);

            imageThumbnail.CreateThumbnail("Tulips.jpg");

            Bitmap bitmap = new Bitmap(Path.Combine(thumbnailDirectory, "thumb-tulips.jpg"));

            Assert.AreEqual(ImageThumbnail.ThumbnailHeight, bitmap.Size.Height);
            Assert.AreEqual(ImageThumbnail.ThumbnailWidth, bitmap.Size.Width);
        }
Esempio n. 8
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
         }
         if (ImageThumbnail != null)
         {
             ImageThumbnail.Dispose();
         }
         ImageThumbnail = null;
         LayerObject    = null;
         Labels         = null;
         _disposed      = true;
     }
 }
Esempio n. 9
0
        public Guid CloneProduct(Guid productId, Guid parentId)
        {
            if (productId == Guid.Empty)
            {
                return(Guid.Empty);
            }

            using (var context = new InstantStoreDataContext())
            {
                var product = context.Products.FirstOrDefault(x => x.VersionId == productId);
                if (product == null)
                {
                    throw new ModelValidationException("Model.Invalid:ProductDoesNotExists");
                }

                var pageCategory = context.ContentPages.FirstOrDefault(x => x.Id == parentId);
                if (pageCategory == null)
                {
                    throw new ModelValidationException("Model.Invalid:ContentPageDoesNotExists");
                }

                if (!pageCategory.IsCategory())
                {
                    throw new ModelValidationException("Model.Invalid:PageIsNotCategory");
                }

                // Build the clone

                var clone = new Product()
                {
                    Id           = Guid.NewGuid(),
                    CashAccepted = product.CashAccepted,
                    Currency     = product.Currency,
                    CustomAttributesTemplateId = product.CustomAttributesTemplateId,
                    Description        = product.Description,
                    Image              = product.Image,
                    IsAvailable        = product.IsAvailable,
                    MainImageId        = product.MainImageId,
                    Name               = product.Name,
                    PriceCurrencyId    = product.PriceCurrencyId,
                    PriceValueCash     = product.PriceValueCash,
                    PriceValueCashless = product.PriceValueCashless,
                    PropertyTemplate   = product.PropertyTemplate,
                    Version            = 1,
                    VersionId          = Guid.NewGuid()
                };

                const string endingStirng     = " - Копия ";
                int          cloneEndingIndex = clone.Name.IndexOf(endingStirng);
                if (cloneEndingIndex > -1)
                {
                    int    indexValue  = 0;
                    string indexString = clone.Name.Substring(cloneEndingIndex + endingStirng.Length);
                    if (!string.IsNullOrEmpty(indexString) && int.TryParse(indexString, out indexValue))
                    {
                        clone.Name = clone.Name.Substring(0, cloneEndingIndex) + endingStirng + indexValue.ToString();
                    }
                    else
                    {
                        clone.Name = clone.Name + endingStirng + "1";
                    }
                }
                else
                {
                    clone.Name = clone.Name + endingStirng + "1";
                }

                // Updating the tables

                context.Products.InsertOnSubmit(clone);

                // Clone images

                var images = context.Images.Where(x => x.ProductId == product.Id);
                if (images.Any())
                {
                    foreach (var image in images)
                    {
                        var clonedImage = new Image {
                            Id               = Guid.NewGuid(),
                            ProductId        = clone.Id,
                            ImageContentType = image.ImageContentType,
                            Image1           = image.Image1
                        };

                        context.Images.InsertOnSubmit(clonedImage);

                        var thumbnail = context.ImageThumbnails.FirstOrDefault(x => x.Id == image.Id);
                        if (thumbnail != null)
                        {
                            var clonedThumbnail = new ImageThumbnail {
                                Id             = clonedImage.Id,
                                Image          = clonedImage,
                                LargeThumbnail = thumbnail.LargeThumbnail,
                                SmallThumbnail = thumbnail.SmallThumbnail
                            };

                            context.ImageThumbnails.InsertOnSubmit(clonedThumbnail);
                        }
                    }
                }

                // Place product in to the same category as original.

                context.ProductToCategories.InsertOnSubmit(new ProductToCategory
                {
                    Id         = Guid.NewGuid(),
                    CategoryId = parentId,
                    ProductId  = clone.VersionId,
                    UpdateTime = DateTime.Now
                });

                CategoryTreeBuilder.RebuidCategoryTreeGroups(context, parentId);
                context.SubmitChanges();

                return(clone.VersionId);
            }
        }