Exemple #1
0
        private void UpdateDetectorImage(DetectorItem i)
        {
            i.xDim = LockedArea.xPixels;
            i.yDim = LockedArea.yPixels;

            i.ImgBmp        = new WriteableBitmap(LockedArea.xPixels, LockedArea.yPixels, 96, 96, PixelFormats.Bgr32, null);
            i.tImage.Source = i.ImgBmp;

            RenderOptions.SetBitmapScalingMode(i.tImage, BitmapScalingMode.NearestNeighbor);

            // Calculate the number of bytes per pixel (should be 4 for this format).
            var bytesPerPixel = (i.ImgBmp.Format.BitsPerPixel + 7) / 8;
            // Stride is bytes per pixel times the number of pixels.
            // Stride is the byte width of a single rectangle row.
            var stride = i.ImgBmp.PixelWidth * bytesPerPixel;

            // Create a byte array for a the entire size of bitmap.
            var arraySize  = stride * i.ImgBmp.PixelHeight;
            var pixelArray = new byte[arraySize];

            var min = i.Min;
            var max = i.Max;

            if (min == max)
            {
                return;
            }

            for (var row = 0; row < i.ImgBmp.PixelHeight; row++)
            {
                for (var col = 0; col < i.ImgBmp.PixelWidth; col++)
                {
                    pixelArray[(row * i.ImgBmp.PixelWidth + col) * bytesPerPixel + 0] = Convert.ToByte(Math.Ceiling(((i.GetClampedPixel(col + row * LockedArea.xPixels) - min) / (max - min)) * 254.0f));
                    pixelArray[(row * i.ImgBmp.PixelWidth + col) * bytesPerPixel + 1] = Convert.ToByte(Math.Ceiling(((i.GetClampedPixel(col + row * LockedArea.xPixels) - min) / (max - min)) * 254.0f));
                    pixelArray[(row * i.ImgBmp.PixelWidth + col) * bytesPerPixel + 2] = Convert.ToByte(Math.Ceiling(((i.GetClampedPixel(col + row * LockedArea.xPixels) - min) / (max - min)) * 254.0f));
                    pixelArray[(row * i.ImgBmp.PixelWidth + col) * bytesPerPixel + 3] = 0;
                }
            }


            var rect = new Int32Rect(0, 0, i.ImgBmp.PixelWidth, i.ImgBmp.PixelHeight);

            i.ImgBmp.WritePixels(rect, pixelArray, stride, 0);
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            if (!goodradii || !isname || !uniquename)
            {
                // show some sort of error
                return;
            }

            // add everything to detector class
            var temp = new DetectorItem(dname)
            {
                Name = dname, Inner = din, Outer = dout, xCentre = dxc, yCentre = dyc, Min = float.MaxValue, Max = 0, ColourIndex = mainDetectors.Count
            };

            // add to the listview
            mainDetectors.Add(temp);
            DetectorListView.Items.Refresh();
            numDet = mainDetectors.Count;

            NameTxtbx.Text = "Detector" + (numDet + 1).ToString();

            // modify the mainWindow List by creating event
            AddDetectorEvent(this, new DetectorArgs(temp));
        }
 public DetectorArgs(DetectorItem s)
 {
     Detector = s;
 }