Exemplo n.º 1
0
        public void AffectImage(Dictionary <String, Object> args)
        {
            Image      image       = (Image)args["DisplayedImage"];
            int        presenterID = (int)args["PresenterID"];
            int        angle       = (int)args["Angle"];
            List <int> presenters  = (List <int>)args["SynchronizedPresenters"];

            image.Bitmap   = SingleBitmapRotation(angle, image.Bitmap);
            image.Rotation = (Rotation)((int)image.Rotation + (int)(angle / 90) % 4);
            RotateImageEvent ri         = new RotateImageEvent();
            IEventAggregator aggregator = GlobalEvent.GetEventAggregator();

            presenters.Add(presenterID);
            ri.Image                  = image;
            ri.PresenterID            = presenterID;
            ri.SynchronizedPresenters = presenters;
            ri.Angle                  = angle;
            aggregator.GetEvent <RotateImageEvent>().Publish(ri);
        }
Exemplo n.º 2
0
        public void AffectImage(Dictionary <String, Object> args)
        {
            Image      image             = (Image)args["DisplayedImage"];
            int        presenterID       = (int)args["PresenterID"];
            List <int> presenters        = (List <int>)args["SynchronizedPresenters"];
            var        transformedBitmap = new TransformedBitmap();

            transformedBitmap.BeginInit();
            transformedBitmap.Source    = image.Bitmap;
            transformedBitmap.Transform = new RotateTransform(90);
            transformedBitmap.EndInit();
            image.Bitmap = transformedBitmap;

            RotateImageEvent ri         = new RotateImageEvent();
            IEventAggregator aggregator = GlobalEvent.GetEventAggregator();

            presenters.Add(presenterID);
            ri.Image                  = image;
            ri.PresenterID            = presenterID;
            ri.SynchronizedPresenters = presenters;
            aggregator.GetEvent <RotateImageEvent>().Publish(ri);
        }
Exemplo n.º 3
0
 public void AffectImage(Dictionary <String, Object> args)
 {
     try
     {
         Image     image         = (Image)args["DisplayedImage"];
         int       mouseX        = (int)((int)args["MouseX"]);
         int       mouseY        = (int)((int)args["MouseY"]);
         int       mouseXDelta   = (int)((int)args["MouseXDelta"]);
         int       mouseYDelta   = (int)((int)args["MouseYDelta"]);
         int       mouseClickX   = (int)((System.Windows.Point)args["MouseClickPosition"]).X;
         int       mouseClickY   = (int)((System.Windows.Point)args["MouseClickPosition"]).Y;
         int       presenterID   = (int)args["PresenterID"];
         Thickness imagePosition = (Thickness)args["Position"];
         int       offsetX       = mouseX - mouseClickX;
         int       offsetY       = mouseY - mouseClickY;
         imagePosition.Left   = imagePosition.Left + offsetX - mouseXDelta;
         imagePosition.Right  = -imagePosition.Left;
         imagePosition.Top    = imagePosition.Top + offsetY - mouseYDelta;
         imagePosition.Bottom = -imagePosition.Top;
         image.Position       = imagePosition;
         IEventAggregator   aggregator = GlobalEvent.GetEventAggregator();
         SendDisplayedImage sdi        = new SendDisplayedImage();
         sdi.Image          = image;
         sdi.PresenterID    = presenterID;
         sdi.IsSynchronized = (bool)args["IsSynchronized"];
         sdi.DoProcessing   = (bool)args["DoProcessing"];
         sdi.OffsetX        = offsetX - mouseXDelta;
         sdi.OffsetY        = offsetY - mouseYDelta;
         sdi.DoReset        = false;
         aggregator.GetEvent <SendDisplayedImage>().Publish(sdi);
     }
     catch (Exception)
     {
         return;
     }
 }
Exemplo n.º 4
0
        public void AffectImage(Dictionary <String, Object> args)
        {
            try
            {
                IEventAggregator     aggregator     = GlobalEvent.GetEventAggregator();
                BitmapWorker         bw             = new BitmapWorker();
                BitmapSource         bitmapSource   = (BitmapSource)args["BitmapSource"];
                System.Windows.Point regionLocation = (System.Windows.Point)args["RegionLocation"];
                int regionWidth  = (int)((int)args["RegionWidth"] * bitmapSource.DpiX / 96.0);
                int regionHeight = (int)((int)args["RegionHeight"] * bitmapSource.DpiY / 96.0);
                if (regionWidth <= 0 || regionHeight <= 0)
                {
                    return;
                }
                Thickness imagePosition = (Thickness)args["ImagePosition"];
                int       ID            = (int)args["PresenterID"];
                double    scale         = (double)args["Scale"];

                int imagePosX = (int)(imagePosition.Left * bitmapSource.DpiX / 96.0);
                int imagePosY = (int)(imagePosition.Top * bitmapSource.DpiY / 96.0);
                int posX      = (int)(regionLocation.X * bitmapSource.DpiX / 96.0);
                int posY      = (int)(regionLocation.Y * bitmapSource.DpiY / 96.0);
                if (regionWidth <= 0 || regionHeight <= 0)
                {
                    return;
                }

                Bitmap bitmap;
                bitmap = bw.GetBitmap(bitmapSource);
                bool isOutside  = false;
                bool isTooSmall = false;
                bitmap = bw.GetBitmapFragment(bitmap, posX, posY, regionWidth, regionHeight, imagePosX, imagePosY, scale, out isOutside, out isTooSmall);

                if (isTooSmall)
                {
                    MessageBox.Show("Witdth or height of a region is less than 1 pixel.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    aggregator.GetEvent <ResetRegionsEvent>().Publish();
                    return;
                }

                bitmap.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ImageViewer\temp" + ID.ToString() + ".png", ImageFormat.Png);
                bitmapSource = bw.BitmapToSource(bitmap);
                int stride;
                int size;
                stride = (bitmapSource.PixelWidth * bitmapSource.Format.BitsPerPixel + 7) / 8;
                size   = bitmapSource.PixelHeight * stride;
                byte[] pixels = new byte[size];
                bitmapSource.CopyPixels(pixels, stride, 0);

                List <byte> alphas = new List <byte>();
                List <byte> reds   = new List <byte>();
                List <byte> greens = new List <byte>();
                List <byte> blues  = new List <byte>();

                for (int i = 0; i < pixels.Length; i += 4)
                {
                    alphas.Add(pixels[i + 3]);
                    reds.Add(pixels[i + 2]);
                    greens.Add(pixels[i + 1]);
                    blues.Add(pixels[i]);
                }
                double[] averages = new double[4];
                averages[0] = 0;
                averages[1] = 0;
                averages[2] = 0;
                averages[3] = 0;
                for (int i = 0; i < alphas.Count; i++)
                {
                    averages[0] += reds[i];
                    averages[1] += greens[i];
                    averages[2] += blues[i];
                    averages[3] += alphas[i];
                }
                averages[0] /= reds.Count;
                averages[1] /= greens.Count;
                averages[2] /= blues.Count;
                averages[3] /= alphas.Count;

                byte[] mins = new byte[4];
                mins[0] = reds.Min();
                mins[1] = greens.Min();
                mins[2] = blues.Min();
                mins[3] = alphas.Min();

                byte[] maxs = new byte[4];
                maxs[0] = reds.Max();
                maxs[1] = greens.Max();
                maxs[2] = blues.Max();
                maxs[3] = alphas.Max();

                double[] variances  = new double[4];
                double[] deviations = new double[4];

                GetVarianceAndDeviation(ref variances, ref deviations, averages, reds, greens, blues, alphas);

                Dictionary <string, Object> regionInformation = new Dictionary <string, Object>();
                regionInformation.Add("Averages", averages);
                regionInformation.Add("Mins", mins);
                regionInformation.Add("Maxs", maxs);
                regionInformation.Add("Width", (int)(bitmap.Width));
                regionInformation.Add("Height", (int)(bitmap.Height));
                regionInformation.Add("Variances", variances);
                regionInformation.Add("Deviations", deviations);
                regionInformation.Add("PresenterID", ID);

                aggregator.GetEvent <SendRegionInformationEvent>().Publish(regionInformation);
            }
            catch (KeyNotFoundException)
            {
            }
        }
Exemplo n.º 5
0
        public void AffectImage(Dictionary <String, Object> args)
        {
            BitmapSource bitmapSource = (BitmapSource)args["BitmapSource"];


            int       mouseX        = (int)((int)args["MouseX"] * bitmapSource.DpiX / 96);
            int       mouseY        = (int)((int)args["MouseY"] * bitmapSource.DpiY / 96);
            double    scale         = (double)args["Scale"];
            Thickness imagePosition = (Thickness)args["ImagePosition"];

            var targetBitmap = new TransformedBitmap(bitmapSource, new ScaleTransform(scale, scale));

            bitmapSource = targetBitmap;

            try
            {
                int    stride = (int)(bitmapSource.PixelWidth * 4);
                int    size   = (int)(bitmapSource.PixelHeight * stride);
                byte[] pixels = new byte[size];
                bitmapSource.CopyPixels(pixels, stride, 0);
                int  row    = mouseY - (int)(imagePosition.Top * bitmapSource.DpiY / 96);
                int  column = mouseX - (int)(imagePosition.Left * bitmapSource.DpiX / 96);
                int  index  = row * stride + 4 * column;
                byte red;
                byte green;
                byte blue;
                byte alpha;

                Dictionary <string, int> pixelInformation = new Dictionary <string, int>();
                if (row >= bitmapSource.PixelHeight || row < 0 || column >= bitmapSource.PixelWidth || column < 0)
                {
                    red   = 0;
                    green = 0;
                    blue  = 0;
                    alpha = 0;
                    pixelInformation.Add("MouseX", -1);
                    pixelInformation.Add("MouseY", -1);
                }
                else
                {
                    red   = pixels[index + 2];
                    green = pixels[index + 1];
                    blue  = pixels[index];
                    alpha = pixels[index + 3];
                    pixelInformation.Add("MouseX", (int)((mouseX - (int)(imagePosition.Left * bitmapSource.DpiX / 96)) / scale));
                    pixelInformation.Add("MouseY", (int)((mouseY - (int)(imagePosition.Top * bitmapSource.DpiY / 96)) / scale));
                }
                pixelInformation.Add("Alpha", alpha);
                pixelInformation.Add("Red", red);
                pixelInformation.Add("Green", green);
                pixelInformation.Add("Blue", blue);

                IEventAggregator aggregator = GlobalEvent.GetEventAggregator();
                aggregator.GetEvent <SendPixelInformationEvent>().Publish(pixelInformation);
            }
            catch (KeyNotFoundException)
            {
                throw;
            }
            catch (IndexOutOfRangeException)
            {
            }
        }