public void MouseLeftButtonDownAction(object sender, MouseButtonEventArgs e)
        {
            ToClientV.MySelf.Visibility = System.Windows.Visibility.Collapsed;
            UIElement rootUI = App.Current.RootVisual;
            WriteableBitmap wb = new WriteableBitmap(rootUI, null);
            int width = wb.PixelWidth;
            int height = wb.PixelHeight;
            int bands = 3;
            byte[][,] raster = new byte[bands][,];
            for (int i = 0; i < bands; i++)
            {
                raster[i] = new byte[width, height];
            }
            for (int row = 0; row < height; row++)
            {
                for (int column = 0; column < width; column++)
                {
                    int pixel = wb.Pixels[width * row + column];
                    raster[0][column, row] = (byte)(pixel >> 16);
                    raster[1][column, row] = (byte)(pixel >> 8);
                    raster[2][column, row] = (byte)pixel;
                }
            }
            FluxJpeg.Core.ColorModel model = new FluxJpeg.Core.ColorModel { colorspace = FluxJpeg.Core.ColorSpace.RGB };
            FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);
            MemoryStream stream = new MemoryStream();
            FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
            encoder.Encode();
            stream.Seek(0, SeekOrigin.Begin);
            byte[] binaryData = stream.ToArray();

            Command.Execute(binaryData);
            ToClientV.MySelf.Visibility = System.Windows.Visibility.Visible;
        }
Example #2
0
        public DecodedJpeg(FluxJpeg.Core.Image image, IEnumerable <JpegHeader> metaHeaders)
        {
            this.Precision         = 8;
            this.HsampFactor       = new int[] { 1, 1, 1 };
            this.VsampFactor       = new int[] { 1, 1, 1 };
            this.lastColumnIsDummy = new bool[3];
            this.lastRowIsDummy    = new bool[3];
            this._image            = image;
            this._metaHeaders      = (metaHeaders == null) ? new List <JpegHeader>(0) : new List <JpegHeader>(metaHeaders);
            foreach (JpegHeader header in this._metaHeaders)
            {
                if (header.IsJFIF)
                {
                    //  this.HasJFIF = true;
                    break;
                }
            }
            int componentCount = this._image.ComponentCount;

            this.compWidth   = new int[componentCount];
            this.compHeight  = new int[componentCount];
            this.BlockWidth  = new int[componentCount];
            this.BlockHeight = new int[componentCount];
            this.Initialize();
        }
        public static bool ResizeNeeded(FluxJpeg.Core.Image image, int maxEdgeLength)
        {
            double scale = (image.Width > image.Height) ?
                           (double)maxEdgeLength / image.Width :
                           (double)maxEdgeLength / image.Height;

            return(scale < 1.0); // true if we must downscale
        }
Example #4
0
        public DecodedJpeg(FluxJpeg.Core.Image image) : this(image, null)
        {
            this._metaHeaders = new List <JpegHeader>();
            string     s    = "Jpeg Codec | fluxcapacity.net ";
            JpegHeader item = new JpegHeader();

            item.Marker = 0xfe;
            item.Data   = Encoding.UTF8.GetBytes(s);
            this._metaHeaders.Add(item);
        }
Example #5
0
        private void SaveToFile(WriteableBitmap bitmap, Stream fs)
        {
            int width  = bitmap.PixelWidth;
            int height = bitmap.PixelHeight;
            int bands  = 3;

            byte[][,] raster = new byte[bands][, ];

            for (int i = 0; i < bands; i++)
            {
                raster[i] = new byte[width, height];
            }

            for (int row = 0; row < height; row++)
            {
                for (int column = 0; column < width; column++)
                {
                    int pixel = bitmap.Pixels[width * row + column];
                    raster[0][column, row] = (byte)(pixel >> 16);
                    raster[1][column, row] = (byte)(pixel >> 8);
                    raster[2][column, row] = (byte)pixel;
                }
            }

            FluxJpeg.Core.ColorModel model = new FluxJpeg.Core.ColorModel {
                colorspace = FluxJpeg.Core.ColorSpace.RGB
            };
            FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);

            //Encode the Image as a JPEG
            MemoryStream stream = new MemoryStream();

            FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
            encoder.Encode();

            //Back to the start
            stream.Seek(0, SeekOrigin.Begin);

            //Get teh Bytes and write them to the stream
            byte[] binaryData = new byte[stream.Length];
            long   bytesRead  = stream.Read(binaryData, 0, (int)stream.Length);

            fs.Write(binaryData, 0, binaryData.Length);
        }
Example #6
0
 public DecodedJpeg(FluxJpeg.Core.Image image, IEnumerable<JpegHeader> metaHeaders)
 {
     this.Precision = 8;
     this.HsampFactor = new int[] { 1, 1, 1 };
     this.VsampFactor = new int[] { 1, 1, 1 };
     this.lastColumnIsDummy = new bool[3];
     this.lastRowIsDummy = new bool[3];
     this._image = image;
     this._metaHeaders = (metaHeaders == null) ? new List<JpegHeader>(0) : new List<JpegHeader>(metaHeaders);
     foreach (JpegHeader header in this._metaHeaders)
     {
         if (header.IsJFIF)
         {
           //  this.HasJFIF = true;
             break;
         }
     }
     int componentCount = this._image.ComponentCount;
     this.compWidth = new int[componentCount];
     this.compHeight = new int[componentCount];
     this.BlockWidth = new int[componentCount];
     this.BlockHeight = new int[componentCount];
     this.Initialize();
 }
        public void MouseLeftButtonUpAction(object sender, MouseButtonEventArgs e)
        {
            if (!ended)
            { return; }
            isPressed = false;
            WriteableBitmap twb = new WriteableBitmap(ShotGrid, null);
            int width = twb.PixelWidth;
            int height = twb.PixelHeight;
            int bands = 3;
            byte[][,] raster = new byte[bands][,];
            for (int i = 0; i < bands; i++)
            {
                raster[i] = new byte[width, height];
            }
            for (int row = 0; row < height; row++)
            {
                for (int column = 0; column < width; column++)
                {
                    int pixel = twb.Pixels[width*row+column];
                    raster[0][column, row] = (byte)(pixel >> 16);
                    raster[1][column, row] = (byte)(pixel >> 8);
                    raster[2][column, row] = (byte)pixel;
                }
            }

            FluxJpeg.Core.ColorModel model = new FluxJpeg.Core.ColorModel { colorspace = FluxJpeg.Core.ColorSpace.RGB };
            FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);
            MemoryStream stream = new MemoryStream();
            FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
            encoder.Encode();
            stream.Seek(0, SeekOrigin.Begin);
            byte[] binaryData = stream.ToArray();
            save.Execute(binaryData);
            p.Children.Remove(this);
            ended = false;
        }