Exemplo n.º 1
0
 private void InitDesignData()
 {
     Dimension = new ImageDimension {
         Width = 500, Height = 500
     };
     _selectedSize = ImageSizes[1];
 }
Exemplo n.º 2
0
        /// <summary>
        /// Finds the image perspective.
        /// </summary>
        /// <param name="photo">The photo.</param>
        /// <param name="maxImageDimension">The max image dimension.</param>
        /// <returns></returns>
        public static ImageDimension FindImagePerspective(Bitmap photo, ImageDimension maxImageDimension)
        {
            ImageDimension dimension = new ImageDimension();

            //determine if it's a portrait or landscape
            if (photo.Height > photo.Width)
            {
                //portrait
                decimal ratio = (photo.Width / (decimal)photo.Height);

                dimension.Height = (photo.Height < maxImageDimension.Height ? photo.Height : maxImageDimension.Height);
                dimension.Width  = (int)(ratio * dimension.Height);

                dimension.PhotoProfile = PhotoProfile.Portrait;
            }
            else
            {
                //landscape
                decimal ratio = (photo.Height / (decimal)photo.Width);

                dimension.Width  = (photo.Width < maxImageDimension.Width ? photo.Width : maxImageDimension.Width);
                dimension.Height = (int)(ratio * dimension.Width);

                dimension.PhotoProfile = PhotoProfile.Landscape;
            }

            return(dimension);
        }
Exemplo n.º 3
0
 private void LookImageReceivedMessageAction(GenericMessage <PortableImage> message)
 {
     Image     = message.Content;
     Dimension = new ImageDimension {
         Height = Image.Height, Width = Image.Width
     };
 }
Exemplo n.º 4
0
        public static string BuildPdf(string imageSource)
        {
            var pdfDestination = Path.Combine(
                Path.GetDirectoryName(imageSource),
                Path.ChangeExtension(imageSource, FileFormat.Pdf));

            var dimension = new ImageDimension(imageSource);

            using (var doc = new PdfDocument())
            {
                doc.Pages.Add(new PdfPage {
                    Height = dimension.Height, Width = dimension.Width
                });

                using (var xGraphics = XGraphics.FromPdfPage(doc.Pages[0]))
                    using (var xImage = XImage.FromFile(imageSource))
                    {
                        xGraphics.DrawImage(xImage, 0, 0, dimension.Width, dimension.Height);
                        doc.Save(pdfDestination);
                    }
            }

            FileHelper.TryDelete(imageSource);

            return(pdfDestination);
        }
Exemplo n.º 5
0
 public ImagePrimitive(Type sampledType, ImageDimension dimension, ImageDepthMode depthMode, ImageArrayedMode arrayedMode, ImageMultiSampledMode multiSampledMode, ImageSampledMode sampledMode, ImageFormat imageFormat)
 {
     SampledType      = sampledType;
     Dimension        = dimension;
     DepthMode        = depthMode;
     ArrayedMode      = arrayedMode;
     MultiSampledMode = multiSampledMode;
     SampledMode      = sampledMode;
     ImageFormat      = imageFormat;
 }
Exemplo n.º 6
0
 public void ClearWindow()
 {
     Ts.Cancel();
     T?.Wait(Ts.Token);
     DataSource.Path  = "FirstTimeNotSet";
     DataSource.Title = "";
     WindowTitle      = "Minimal CS Manga Reader";
     DataSource.ImageList.Clear();
     DataSource.ChapterList.Clear();
     ImageHeight.Clear();
     ImageDimension.Clear();
     //Save
     Config.Path = DataSource.Path;
     Config.Save();
 }
Exemplo n.º 7
0
        private ItemThumbnail CreateItemThumbnail(FileInfo file)
        {
            ItemThumbnail item;

            if (Setting.ImageExtensions.Contains(file.Extension))
            {
                var dimension = ImageDimension.GetDimensions(file.FullName);
                item = new ItemThumbnail(file.FullName, file.Name, file.Extension, dimension, (file.Length / 1000).ToString());
            }
            else
            {
                item = new ItemThumbnail(file.FullName, file.Name, file.Extension, null, (file.Length / 1000).ToString());
            }

            return(item);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Resizes the bitmap, pass in the new sizes
        /// </summary>
        /// <param name="bitmap">bitmap to be resized</param>
        /// <param name="dimensions">The dimensions.</param>
        /// <returns></returns>
        public static Bitmap Resize(Bitmap bitmap, ImageDimension dimensions)
        {
            Bitmap result = new Bitmap(dimensions.Width, dimensions.Height);

            using (Graphics graphic = Graphics.FromImage(result))
            {
                graphic.SmoothingMode      = SmoothingMode.HighQuality;
                graphic.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphic.CompositingQuality = CompositingQuality.HighQuality;
                graphic.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                graphic.DrawImage(bitmap, 0, 0, dimensions.Width, dimensions.Height);
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary> Gets image dimension. </summary>
        /// <remarks> Doetsch, 20.03.20. </remarks>
        /// <param name="pImage"> The image. </param>
        /// <returns> The image dimension. </returns>
        private static ImageDimension GetImageDimension(Image pImage)
        {
            var lImageDimension = new ImageDimension();

            if (pImage.Height < pImage.Width)
            {
                lImageDimension.Width  = cMaxDimension;
                lImageDimension.Height = (cMaxDimension / (double)pImage.Width) * pImage.Height;
            }
            else
            {
                lImageDimension.Height = cMaxDimension;
                lImageDimension.Width  = (cMaxDimension / (double)pImage.Height) * pImage.Width;
            }

            return(lImageDimension);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Resizes the specified bitmap.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <param name="dimensions">The dimensions.</param>
        /// <returns></returns>
        public static byte[] Resize(byte[] bitmap, ImageDimension dimensions)
        {
            byte[] imageBytes;

            Bitmap image = ConvertByteArrayToBitmap(bitmap);

            image = Resize(image, dimensions);

            using (MemoryStream outStream = new MemoryStream())
            {
                image.Save(outStream, ImageFormat.Jpeg);
                outStream.Position = 0;
                imageBytes         = new byte[outStream.Length];
                outStream.Read(imageBytes, 0, (int)outStream.Length);
            }

            return(imageBytes);
        }
Exemplo n.º 11
0
        private async Task SaveAction()
        {
            string validName = await ServiceLocator.ContextService.ConvertToValidFileName(LookName);

            List <string> nameList = new List <string>();

            foreach (var lookItem in _receivedSelectedSprite.Looks)
            {
                nameList.Add(lookItem.Name);
            }
            LookName = await ServiceLocator.ContextService.FindUniqueName(validName, nameList);

            var message = new GenericMessage <PortableImage>(Image);

            Messenger.Default.Send(message, ViewModelMessagingToken.LookImageToSaveListener);

            ServiceLocator.DispatcherService.RunOnMainThread(() =>
            {
                ServiceLocator.NavigationService.RemoveBackEntry();
                ServiceLocator.NavigationService.NavigateBack(this.GetType());
            });

            //ServiceLocator.DispatcherService.RunOnMainThread(() =>
            //    ServiceLocator.NavigationService.NavigateTo<LookSavingViewModel>());

            var newDimention = new ImageDimension
            {
                Height = SelectedSize.NewHeight,
                Width  = SelectedSize.NewWidth
            };

            var look = await LookHelper.Save(Image, LookName, newDimention, CurrentProgram.BasePath);

            ServiceLocator.DispatcherService.RunOnMainThread(() =>
            {
                _receivedSelectedSprite.Looks.Add(look);
                //ServiceLocator.NavigationService.RemoveBackEntryForPlatform(NavigationPlatform.WindowsPhone);
                //ServiceLocator.NavigationService.RemoveBackEntryForPlatform(NavigationPlatform.WindowsPhone);
                ResetViewModel();
                //ServiceLocator.NavigationService.NavigateBack(
                //    new List<NavigationPlatform>{NavigationPlatform.WindowsStore});
            });
        }
Exemplo n.º 12
0
        public static async Task <Look> Save(PortableImage image, string name, ImageDimension dimension, string projectPath)
        {
            using (var storage = StorageSystem.GetStorage())
            {
                var imagePath = Path.Combine(projectPath, StorageConstants.ProgramLooksPath);
                if (!await storage.DirectoryExistsAsync(imagePath))
                {
                    await storage.CreateDirectoryAsync(imagePath);
                }
            }

            var resizedImage = await ServiceLocator.ImageResizeService.ResizeImage(image, dimension.Width, dimension.Height);

            var look             = new Look(name);
            var absoluteFileName = Path.Combine(projectPath, StorageConstants.ProgramLooksPath, look.FileName);

            await resizedImage.WriteAsPng(absoluteFileName);

            //look.Image = resizedImage;

            return(look);
        }
Exemplo n.º 13
0
 public async Task UpdateAsync()
 {
     if (ChapterList.Count > 0)
     {
         Ts.Cancel();
         T?.Wait(Ts.Token);
         Ts = new CancellationTokenSource();
         ImageHeight.Clear();
         ImageDimension.Clear();
         ScrollHelper.Helper();
         T = await Task.Run(async() =>
         {
             await DataSource.PopulateImageAsync(_chapterList[ActiveIndex], Ts.Token).ConfigureAwait(false);
             return(T);
         }).ConfigureAwait(false);
     }
     else
     {
         DataSource.ImageList.Clear();
         ImageHeight.Clear();
         ImageDimension.Clear();
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Inserts the specified photo.
        /// </summary>
        /// <param name="photo">The photo.</param>
        /// <param name="galleryPhoto">The gallery photo.</param>
        public void Insert(Photo photo, GalleryPhoto galleryPhoto)
        {
            GalleryPhoto adminPhotos = new GalleryPhoto();

            GallerySettings settings      = GallerySettings.Load();
            Bitmap          orginalBitmap = ImageConversion.ConvertByteArrayToBitmap(galleryPhoto.OriginalImage);

            //hardcoded administration image dimensions. This will allow the user to change their image sizes and not have it effect my pretty admin layout.
            ImageDimension adminThumbnailDimensions = new ImageDimension {
                Height = 100, Width = 100
            };
            ImageDimension adminFullsizeDimensions = new ImageDimension {
                Height = 600, Width = 600
            };

            adminThumbnailDimensions = FindImagePerspective(orginalBitmap, adminThumbnailDimensions);
            adminFullsizeDimensions  = FindImagePerspective(orginalBitmap, adminFullsizeDimensions);

            //Resize the Admin images
            adminPhotos.ThumbnailImage = ImageConversion.Resize(galleryPhoto.OriginalImage, adminThumbnailDimensions);
            adminPhotos.DisplayImage   = ImageConversion.Resize(galleryPhoto.OriginalImage, adminFullsizeDimensions);

            //calculate the correct dimensions
            ImageDimension thumbnailDimensions = FindImagePerspective(orginalBitmap, settings.ThumbnailDimensions);
            ImageDimension fullsizeDimensions  = FindImagePerspective(orginalBitmap, settings.FullsizeDimensions);

            //Resize the images
            galleryPhoto.ThumbnailImage = ImageConversion.Resize(galleryPhoto.OriginalImage, thumbnailDimensions);
            galleryPhoto.DisplayImage   = ImageConversion.Resize(galleryPhoto.OriginalImage, fullsizeDimensions);

            //Set photo profile
            photo.Profile = fullsizeDimensions.PhotoProfile;

            //Insert new images into the Database
            _resource.Insert(photo, galleryPhoto, adminPhotos);
        }
Exemplo n.º 15
0
 public ImagePrimitive(Type sampledType, ImageDimension dimension, ImageFormat imageFormat)
 {
     SampledType = sampledType;
     Dimension   = dimension;
     ImageFormat = imageFormat;
 }