Ejemplo n.º 1
0
        public ProcessImage Encode(SKImage img, ProcessImageType toType, bool flipHorizontal, bool flipVertical)
        {
            if (flipHorizontal || flipVertical)
            {
                using SKBitmap bmp     = new SKBitmap(img.Width, img.Height);
                using SKCanvas surface = new SKCanvas(bmp);
                surface.Scale(flipHorizontal ? -1 : 1, flipVertical ? -1 : 1, flipHorizontal ? img.Width / 2f : 0, flipVertical ? img.Height / 2f : 0);
                surface.DrawImage(img, 0, 0);
                img = SKImage.FromBitmap(bmp);
            }

            if (toType == ProcessImageType.JPEG)
            {
                return(new ProcessImage {
                    Load = img.Encode(SKEncodedImageFormat.Jpeg, 95).ToArray(), Type = toType, Width = img.Width, Height = img.Height
                });
            }
            if (toType == ProcessImageType.PNG)
            {
                return(new ProcessImage {
                    Load = img.Encode(SKEncodedImageFormat.Png, 95).ToArray(), Type = toType, Width = img.Width, Height = img.Height
                });
            }
            if (toType == ProcessImageType.RGBA8)
            {
                SKBitmap bmp = SKBitmap.FromImage(img);
                return(new ProcessImage {
                    Load = bmp.Bytes, Height = bmp.Height, Type = toType, Width = bmp.Width
                });
            }
            throw new FormatException("Format conversion not implemented");
        }
Ejemplo n.º 2
0
        public ProcessImage Convert(ProcessImage source, ProcessImageType target, bool flipHorizontal = false, bool flipVertical = false)
        {
            if (source.Type == target)
            {
                return(source);
            }

            if (source.Type == ProcessImageType.PNG)
            {
                return(Encode(SKImage.FromBitmap(SKBitmap.Decode(source.Load)), target, flipHorizontal, flipVertical));
            }
            if (source.Type == ProcessImageType.Grayscale8)
            {
                return(Encode(SKImage.FromPixelCopy(new SKImageInfo(source.Width, source.Height, SKColorType.Gray8), source.Load), target, flipHorizontal, flipVertical));
            }
            if (source.Type == ProcessImageType.RGBA8)
            {
                return(Encode(SKImage.FromPixelCopy(new SKImageInfo(source.Width, source.Height, SKColorType.Rgba8888), source.Load), target, flipHorizontal, flipVertical));
            }
            if (source.Type == ProcessImageType.RGBA16)
            {
                return(Encode(SKImage.FromPixelCopy(new SKImageInfo(source.Width, source.Height, SKColorType.RgbaF16), source.Load), target, flipHorizontal, flipVertical));
            }

            /*if (source.Type == ProcessImageType.RGBA32)
             * {
             *  Image img = Image.LoadPixelData<RgbaVector>(source.Load, source.Width, source.Height);
             *  if (flipHorizontal) { img.Mutate(x => x.Flip(FlipMode.Horizontal)); }
             *  if (flipVertical) { img.Mutate(x => x.Flip(FlipMode.Vertical)); }
             *  return Encode(img, target);
             * }*/

            throw new FormatException("Format conversion not implemented");
        }
Ejemplo n.º 3
0
 public ProcessImage(byte[] load, ProcessImageType type, int width, int height) : this(load, type)
 {
     Width = width; Height = height;
 }
Ejemplo n.º 4
0
 public ProcessImage(byte[] load, ProcessImageType type)
 {
     Load = load; Type = type;
 }