示例#1
0
        public void Execute()
        {
            var colors     = _colorReaderService.GetAllColors();
            var colorCount = 1;

            _folderService.ClearFolder(FolderName);

            foreach (var color in colors)
            {
                Console.WriteLine($"Working on file {colorCount}");

                var temporaryFolder = _folderService.GetTemporaryDirectory();

                var documentCreator = new DocumentFileCreator(color);
                documentCreator.CreateFile(temporaryFolder);

                var documentPropertiesCreator = new DocumentPropertiesFileCreator(color);
                documentPropertiesCreator.CreateFile(temporaryFolder);

                var thumbnailCreator = new ThumbnailCreator(color);
                thumbnailCreator.CreateThumbnail(temporaryFolder);

                var referenceCreator = new ReferenceFileCreator();
                referenceCreator.CreateFile(temporaryFolder);

                var materialArchive = new MaterialArchiveService(temporaryFolder, FolderName);
                materialArchive.CreateArchive(color.Name);

                colorCount++;
            }
        }
示例#2
0
 public ThumbnailGenerator()
 {
     disposed       = false;
     tg             = new ThumbnailCreator();
     tg.DesiredSize = new Size(THUMB_SIZE, THUMB_SIZE);
     thumbnail      = null;
 }
示例#3
0
 private void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             tg.Dispose();
         }
         tg = null;
     }
     disposed = true;
 }
示例#4
0
文件: Program.cs 项目: radtek/HinxCor
 private void workImageStream(string fileName)
 {
     byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
         thumbnailSize: 300,
         imageStream: new FileStream(@"C:\images\image.jpg", FileMode.Open, FileAccess.ReadWrite),
         imageFormat: Format.Jpeg);
     //or
     Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(
         thumbnailSize: 300,
         imageStream: new FileStream(@"C:\images\image.jpg", FileMode.Open, FileAccess.ReadWrite),
         imageFormat: Format.Jpeg);
 }
示例#5
0
文件: Program.cs 项目: radtek/HinxCor
 private void workImageLocal(string fileName)
 {
     byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
         thumbnailSize: 300,
         imageFileLocation: @"C:\images\image.bmp",
         imageFormat: Format.Bmp);
     //or
     Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(
         thumbnailSize: 300,
         imageFileLocation: @"C:\images\image.bmp",
         imageFormat: Format.Bmp);
 }
示例#6
0
        public byte[] createThumb(BitmapImage image)
        {
            MemoryStream      mem    = new MemoryStream();
            JpegBitmapEncoder encode = new JpegBitmapEncoder();

            encode.Frames.Add(BitmapFrame.Create(image));
            encode.Save(mem);

            byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(

                thumbnailSize: 50,
                imageBytes: mem.ToArray(),
                imageFormat: Format.Png
                );
            return(resultBytes);
        }
示例#7
0
文件: Program.cs 项目: radtek/HinxCor
        private void workImageStream(byte[] buffer)
        {
            //byte[] buffer = GetImageBytes(); //this is just fictitious method to get image data in bytes

            byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
                thumbnailSize: 300,
                imageBytes: buffer,
                imageFormat: Format.Gif
                );
            //or
            Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(
                thumbnailSize: 300,
                imageBytes: buffer,
                imageFormat: Format.Tiff
                );
        }
示例#8
0
        private void ExecuteCommand(Uri source, string target, uint size, Format format)
        {
            Console.WriteLine("Downloading image...");
            bool success = false;

            try
            {
                ThumbnailCreator thumbnailCreator = new ThumbnailCreator();
                using (Stream sourceStream = thumbnailCreator.CreateThumbnailStreamAsync(size, source, format).Result)
                {
                    if (sourceStream != null)
                    {
                        Console.WriteLine("Processing...");
                        using (FileStream fs = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            if (sourceStream.Position != 0)
                            {
                                sourceStream.Position = 0;
                            }

                            sourceStream.CopyTo(fs);
                            success = true;
                        }
                    }
                    else
                    {
                        success = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                success = false;
            }
            finally
            {
                if (success)
                {
                    Console.WriteLine("Thumbnail created successfully...");
                }
                else
                {
                    Console.WriteLine("Operation was not completed successfully...");
                }
            }
        }
        public byte[] CreateThumbnail(BitmapImage imageC)
        {
            //Read Image byte

            MemoryStream      memStream = new MemoryStream();
            JpegBitmapEncoder encoder   = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(imageC));
            encoder.Save(memStream);

            //Create Thumbnail from image

            byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
                thumbnailSize: 450,
                imageBytes: memStream.ToArray(),
                imageFormat: Format.Jpeg
                );
            return(resultBytes);
        }
示例#10
0
        public RecipeStepBase(IBaseSettings settings, ILogger logger)
        {
            this._settings = settings;
            this._logger   = logger;

            this.Photo.Where(x => x != null).Subscribe(x => {
                using (var crypto = new SHA256CryptoServiceProvider()) {
                    var filePath             = string.Join("", crypto.ComputeHash(x).Select(b => $"{b:X2}")) + ".png";
                    this.PhotoFilePath.Value = filePath;

                    this.Thumbnail.Value         = ThumbnailCreator.Create(x, 100, 100);
                    var thumbFilePath            = string.Join("", crypto.ComputeHash(this.Thumbnail.Value).Select(b => $"{b:X2}")) + ".png";
                    this.ThumbnailFilePath.Value = thumbFilePath;
                }
            });

            this.PhotoFilePath.Where(x => x != null).ObserveOnDispatcher(DispatcherPriority.Background).ObserveOn(TaskPoolScheduler.Default).Subscribe(x => {
                var fullpath = Path.Combine(this._settings.GeneralSettings.ImageDirectoryPath, x);

                if (!File.Exists(fullpath))
                {
                    File.WriteAllBytes(fullpath, this.Photo.Value);
                }
                else
                {
                    this.Photo.Value = File.ReadAllBytes(fullpath);
                }
            });

            this.ThumbnailFilePath.Where(x => x != null).ObserveOnDispatcher(DispatcherPriority.Background).ObserveOn(TaskPoolScheduler.Default).Subscribe(x => {
                var fullpath = Path.Combine(this._settings.GeneralSettings.ImageDirectoryPath, x);
                if (this.Thumbnail.Value != null && !File.Exists(fullpath))
                {
                    File.WriteAllBytes(fullpath, this.Thumbnail.Value);
                }
                else
                {
                    this.Thumbnail.Value = File.ReadAllBytes(fullpath);
                }
            });
        }
示例#11
0
        public GetArtwork()
        {
            Get["/artwork"] = _ =>
            {
                Plugin.MusicBeeApiInterface mbApi            = MbApiInstance.Instance.MusicBeeApiInterface;
                PictureLocations            pictureLocations = PictureLocations.None;
                string[] album = null;
                mbApi.Library_QueryFilesEx($"Artist={Request.Query.artist}\0Album={Request.Query.album}", ref album);
                string pictureUrl = null;
                byte[] image      = null;
                mbApi.Library_GetArtworkEx(album[0], 0, true, ref pictureLocations, ref pictureUrl, ref image);

                if (Request.Query.thumbnail)
                {
                    try
                    {
                        byte[] thumbnail = new ThumbnailCreator().CreateThumbnailBytes(thumbnailSize: 400, imageBytes: image, imageFormat: Format.Jpeg);
                        string color     = GetColor(thumbnail);
                        return(WriteJson(Convert.ToBase64String(thumbnail), false, color));
                    }
                    catch (Exception e)
                    {
                        if (e.Message == "Thumbnail size must be less than image's size")
                        {
                            string color = GetColor(image);
                            return(WriteJson(Convert.ToBase64String(image), false, color));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(Convert.ToBase64String(image));
                }
            };
        }
        public ActionResult Thumbnail(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var image = files.ImageByPath(path);

            if (image != null)
            {
                var desiredSize = new ImageSize {
                    Width = ThumbnailWidth, Height = ThumbnailHeight
                };

                const string contentType = "image/png";

                var thumbnailCreator = new ThumbnailCreator(new FitImageResizer());

                using (var stream = new MemoryStream(image.Image1.ToArray()))
                {
                    return(File(thumbnailCreator.Create(stream, desiredSize, contentType), contentType));
                }
            }
            throw new HttpException(404, "File Not Found");
        }
示例#13
0
 public ImageBrowserController()
 {
     directoryBrowser   = new DirectoryBrowser();
     contentInitializer = new ContentInitializer(contentFolderRoot, foldersToCopy, prettyName);
     thumbnailCreator   = new ThumbnailCreator();
 }
示例#14
0
 public ImageBrowserController()
 {
     _directoryBrowser = new DirectoryBrowser();
     _thumbnailCreator = new ThumbnailCreator();
 }
        private async Task HandleLocalRequest()
        {
            if (!File.Exists(ThumbModel.Location))
            {
                OnError(string.Format(LanguageResource.Instance["FileNotFoundError"], ThumbModel.Location));
            }
            else
            {
                string errorDescription = LanguageResource.Instance["ErrorDescription"];
                if (!Directory.Exists(Path.GetDirectoryName(ThumbModel.TargetLocation)))
                {
                    OnError(string.Format(LanguageResource.Instance["DirectoryNotFoundError"], Path.GetDirectoryName(ThumbModel.TargetLocation)));
                }
                else
                {
                    Format format  = GetFormat(ThumbModel.Format.ToLower());
                    bool   success = false;
                    try
                    {
                        await Task.Run(async() =>
                        {
                            using (Stream sourceStream = new ThumbnailCreator().CreateThumbnailStream(ThumbModel.ThumbnailSize, ThumbModel.Location, format))
                            {
                                if (sourceStream != null)
                                {
                                    using (FileStream fs = new FileStream(ThumbModel.TargetLocation, FileMode.OpenOrCreate, FileAccess.Write))
                                    {
                                        if (sourceStream.Position != 0)
                                        {
                                            sourceStream.Position = 0;
                                        }

                                        await sourceStream.CopyToAsync(fs);
                                        success = true;
                                    }
                                }
                                else
                                {
                                    success = false;
                                }
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        errorDescription += $"\n{ex.Message}\n";
                        success           = false;
                    }
                    finally
                    {
                        if (success)
                        {
                            OnCompleted(LanguageResource.Instance["OnCompletedSuccessful"]);
                        }
                        else
                        {
                            string message = errorDescription + "\n" + LanguageResource.Instance["OnCompletedFailed"];
                            OnCompleted(message);
                        }
                    }
                }
            }
        }
示例#16
0
		internal void StopThumbnailCreation()
		{
			if (thumbCreator != null) {
				thumbCreator.Stop();
				thumbCreator = null;
			}
		}
示例#17
0
		public void RealFileViewUpdate (ArrayList directoriesArrayList, ArrayList fileArrayList)
		{
			BeginUpdate ();
			
			DeleteOldThumbnails ();	// any existing thumbnail images need to be Dispose()d.
			Items.Clear ();
			SelectedItems.Clear ();
			
			foreach (FSEntry directoryFSEntry in directoriesArrayList) {
				if (!ShowHiddenFiles)
					if (directoryFSEntry.Name.StartsWith (".") || (directoryFSEntry.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
						continue;
				
				FileViewListViewItem listViewItem = new FileViewListViewItem (directoryFSEntry);
				
				Items.Add (listViewItem);
			}
			
			StringCollection collection = new StringCollection ();
			
			foreach (FSEntry fsEntry in fileArrayList) {
				
				// remove duplicates. that can happen when you read recently used files for example
				if (collection.Contains (fsEntry.Name)) {
					
					string fileName = fsEntry.Name;
					
					if (collection.Contains (fileName)) {
						int i = 1;
						
						while (collection.Contains (fileName + "(" + i + ")")) {
							i++;
						}
						
						fileName = fileName + "(" + i + ")";
					}
					
					fsEntry.Name = fileName;
				}
				
				collection.Add (fsEntry.Name);
				
				DoOneFSEntry (fsEntry);
			}
			
			EndUpdate ();
			
			collection.Clear ();
			collection = null;
			
			directoriesArrayList.Clear ();
			fileArrayList.Clear ();

			// Create thumbnail images for Image type files.  This greatly facilitates
			// choosing pictures whose names mean nothing.
			// See https://bugzilla.xamarin.com/show_bug.cgi?id=28025 for details.
			thumbCreator = new ThumbnailCreator(new ThumbnailDelegate(RedrawTheItem), this);
			var makeThumbnails = new Thread(new ThreadStart(thumbCreator.MakeThumbnails));
			makeThumbnails.IsBackground = true;
			makeThumbnails.Start();
		}
示例#18
0
 public ImageBrowserController()
 {
     directoryBrowser = new DirectoryBrowser();
     thumbnailCreator = new ThumbnailCreator(new FitImageResizer());
 }