Beispiel #1
0
        public BitmapImage GetEditedBitmapImage()
        {
            if (ImageEdited == null)
            {
                return(null);
            }

            return(ImageTools.ConvertImageToBitmapImage(ImageEdited));
        }
Beispiel #2
0
        public BitmapImage ApplyImageOptions(int?Width, int?Height, bool?Cropping, bool?Flip)
        {
            Width    = (Width == null) ? 0 : Width;
            Height   = (Height == null) ? 0 : Height;
            Cropping = (Cropping == null) ? false : Cropping;


            if (Width == 0 && Height == 0)
            {
                Width  = ImageOriginal.Width;
                Height = ImageOriginal.Height;
            }


            ImageEdited = ImageOriginal;

            if ((bool)Cropping)
            {
                if (Width == 0 || Height == 0)
                {
                    return(null);
                }

                ImageEdited = ImageOriginal.ScaleAndCrop((int)Width, (int)Height);
            }
            else
            {
                // Resize
                if (Width == 0)
                {
                    ImageEdited = ImageOriginal.ScaleByHeight((int)Height);
                }
                else if (Height == 0)
                {
                    ImageEdited = ImageOriginal.ScaleByWidth((int)Width);
                }
                else
                {
                    ImageEdited = ImageOriginal.Scale((int)Width, (int)Height);
                }
            }

            if (ImageEdited != null && (bool)Flip)
            {
                ImageEdited.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }

            if (ImageEdited == null)
            {
                return(null);
            }
            return(ImageTools.ConvertImageToBitmapImage(ImageEdited));
        }
Beispiel #3
0
        public BitmapImage ApplyImageOptions(string FileTempPath, int?Width, int?Height, bool?Cropping, bool?Flip)
        {
            Width    = (Width == null) ? 0 : Width;
            Height   = (Height == null) ? 0 : Height;
            Cropping = (Cropping == null) ? false : Cropping;

            Image ImageScale = null;

            try
            {
                using (Stream stream = FileSystem.OpenReadFileStreamSafe(FileTempPath))
                {
                    ImageScale = Image.FromStream(stream);
                }
            }
            catch (Exception ex)
            {
                Common.LogError(ex, false, true, "LibraryManagement");
                return(null);
            }


            if (Width == 0 && Height == 0)
            {
                Width  = ImageScale.Width;
                Height = ImageScale.Height;
            }


            ImageEdited = null;

            if ((bool)Cropping)
            {
                if (Width == 0 || Height == 0)
                {
                    return(null);
                }

                ImageEdited = ImageScale.ScaleAndCrop((int)Width, (int)Height);
            }
            else
            {
                // Resize
                if (Width == 0)
                {
                    ImageEdited = ImageScale.ScaleByHeight((int)Height);
                }
                else if (Height == 0)
                {
                    ImageEdited = ImageScale.ScaleByWidth((int)Width);
                }
                else
                {
                    ImageEdited = ImageScale.Scale((int)Width, (int)Height);
                }
            }

            if (ImageEdited != null && (bool)Flip)
            {
                ImageEdited.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }

            if (ImageEdited == null)
            {
                return(null);
            }
            return(ImageTools.ConvertImageToBitmapImage(ImageEdited));
        }