Пример #1
0
        public static FormatConvertedBitmap GetFormatConvertedBitmap(SWM.PixelFormat pf, BitmapSource bs)
        {
            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
            newFormatedBitmapSource.BeginInit();
            newFormatedBitmapSource.Source = bs;
            newFormatedBitmapSource.DestinationFormat = pf;
            newFormatedBitmapSource.EndInit();

            return newFormatedBitmapSource;
        }
Пример #2
0
		public static swm.Brush ToWpfBrush(this Color value, swm.Brush brush)
		{
			var solidBrush = brush as swm.SolidColorBrush;
			if (solidBrush == null || solidBrush.IsSealed)
			{
				solidBrush = new swm.SolidColorBrush();
			}
			solidBrush.Color = value.ToWpf();
			return solidBrush;
		}
        protected override void Render(Media.DrawingContext dc)
        {
            dc.DrawRectangle(
                new Media.SolidColorBrush(Theme.Palette[Color.Base03]),
                null, new Rect(0, 0, Width, Height)
                );

            if (Visual is null)
            {
                return;
            }

            // Background
            for (int j = 0; j < Visual.Height; j++) // Go row by row
            {
                int cursorX = 0;
                for (int i = 0; i < Visual.Width; i++)
                {
                    if (Visual[i, j].Back != Visual[cursorX, j].Back)
                    {
                        DrawBackground(cursorX, j, i - cursorX, dc);
                        cursorX = i;
                    }
                }
                DrawBackground(cursorX, j, Visual.Width - cursorX, dc);;
            }

            for (int j = 0; j < Visual.Height; j++)
            {
                string text = ConcatenateLine(Visual, j);

                Media.FormattedText formattedText = new Media.FormattedText(
                    text,
                    CultureInfo.GetCultureInfo("en-us"),
                    FlowDirection.LeftToRight,
                    typeface,
                    emSize,
                    new Media.SolidColorBrush(GetColor(Visual ![0, j].Fore)),
Пример #4
0
		public static ImageInterpolation Convert (swm.BitmapScalingMode value)
		{
			switch (value) {
			case swm.BitmapScalingMode.HighQuality:
				return ImageInterpolation.High;
			case swm.BitmapScalingMode.LowQuality:
				return ImageInterpolation.Low;
			case swm.BitmapScalingMode.NearestNeighbor:
				return ImageInterpolation.None;
			case swm.BitmapScalingMode.Unspecified:
				return ImageInterpolation.Default;
			default:
				throw new NotSupportedException ();
			}
		}
 private void HighlightButton(WPF.ImageButton button, Media.SolidColorBrush highlightBrush, Media.SolidColorBrush borderBrush)
 {
     button.Background = highlightBrush;
     button.BorderBrush = borderBrush;
 }
        /// <summary>
        ///     Raw  Left==Helix Front
        /// </summary>
        /// <param name="plotModel"></param>
        /// <param name="brush"></param>
        /// <param name="currentPosition"></param>
        private void CreateLeftSlice(Model3DGroup plotModel, sysMedia.Brush brush, double currentPosition)
        {
            var position = currentPosition * _realRect3D.SizeY;
            var sectionMeshBuilder = new MeshBuilder();
            sectionMeshBuilder.AddRectangularMesh(
                new[]
                {
                    new Point3D(0, position, _realRect3D.SizeZ),
                    new Point3D(_realRect3D.SizeX, position, _realRect3D.SizeZ),
                    new Point3D(0, position, 0),
                    new Point3D(_realRect3D.SizeX, position, 0)
                }, 2);
            plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(),
                MaterialHelper.CreateMaterial(brush)));

            sectionMeshBuilder = new MeshBuilder();
            sectionMeshBuilder.AddRectangularMesh(
                new[]
                {
                    new Point3D(_realRect3D.SizeX, position, _realRect3D.SizeZ),
                    new Point3D(0, position, _realRect3D.SizeZ),
                    new Point3D(_realRect3D.SizeX, position, 0),
                    new Point3D(0, position, 0)
                }, 2);

            var bgBrush = FilpAndRotateImageBrush(brush);
            plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(),
                MaterialHelper.CreateMaterial(bgBrush)));
        }
 private void CreateTopSelectionSlice(Model3DGroup plotModel, sysMedia.Brush brush)
 {
     if (SectionPosition == 0.0)
     {
         CreateTopMinSlice(plotModel);
     }
     else
     {
         CreateTopSlice(plotModel, brush, SectionPosition);
     }
 }
Пример #8
0
        public static BitmapSource ConvertArrayToBitmapSource(byte[] data, int w, int h, SWM.PixelFormat pixelFormat)
        {
            int ch = 1;

            if (pixelFormat == SWM.PixelFormats.Gray8) ch = 1; //grey scale image 0-255
            if (pixelFormat == SWM.PixelFormats.Bgr24) ch = 3; //RGB
            if (pixelFormat == SWM.PixelFormats.Bgr32) ch = 4; //RGB + alpha

            WriteableBitmap wbm = new WriteableBitmap(w, h, 96, 96, pixelFormat, null);
            wbm.WritePixels(new Int32Rect(0, 0, w, h), data, ch * w, 0);

            return wbm;
        }
 private sysMedia.Brush FilpImageBrush(sysMedia.Brush brush)
 {
     var bgBrush = brush.Clone();
     var transform = sysMedia.Matrix.Identity;
     transform.ScaleAt(1, -1, 0.5, 0.5);
     if (bgBrush is sysMedia.ImageBrush)
     {
         bgBrush.RelativeTransform = new sysMedia.MatrixTransform(transform);
     }
     return bgBrush;
 }
Пример #10
0
		public void Draw (ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
		{
			if (drawCallback != null) {
				DrawingContext c = new DrawingContext (dc, scaleFactor);
				actx.InvokeUserCode (delegate {
					drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height));
				});
			}
			else {
				if (idesc.Alpha < 1)
					dc.PushOpacity (idesc.Alpha);

				var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
				var bmpImage = f as BitmapSource;
				if (bmpImage != null && (bmpImage.PixelHeight != idesc.Size.Height || bmpImage.PixelWidth != idesc.Size.Width))
					f = new TransformedBitmap (bmpImage, new ScaleTransform (idesc.Size.Width / bmpImage.PixelWidth, idesc.Size.Height / bmpImage.PixelHeight));
				dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

				if (idesc.Alpha < 1)
					dc.Pop ();
			}
		}
Пример #11
0
     public static Media.Imaging.BitmapSource ToBitmapSource(this short[] data
 , Media.PixelFormat format, int width, int height)
     {
         return Media.Imaging.BitmapSource.Create(width, height, 96, 96
             , format, null, data, width * format.BitsPerPixel / 8);
     }
Пример #12
0
        // Creates a run based on the letter correctness, green for correct, red for incorrect
        public Run CreateRun(Char letter, Media.Color color)
        {
            Run letterRun = new Run();
            letterRun.Text = letter.ToString();
            letterRun.Text = letter.ToString();

            letterRun.Foreground = new SolidColorBrush(color);
            return letterRun;
        }
Пример #13
0
        //vsual 可以是 FrameworkElement 
        public static RenderTargetBitmap RenderVisaulToBitmap(SWM.Visual vsual, int width, int height)
        {
            RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96, 96, SWM.PixelFormats.Rgb24);
            rtb.Render(vsual);

            return rtb;
        }
Пример #14
0
        //vsual 可以是 FrameworkElement 
        public static bool SaveRenderTargetBitmapToImgFile(string filePathWithoutExtension, SWM.Visual vsual, int widhth, int height, ImageFormat imgFormat)
        {
            if (vsual == null)
                return false;

            string filePath = filePathWithoutExtension + "." + ResourceMap.ImageFormatExtensionHashtable[imgFormat];
            BitmapEncoder encoder = ResourceMap.ImageFormatBitmapEncoderHashtable[imgFormat] as BitmapEncoder;

            if (encoder == null)
                return false;

            RenderTargetBitmap rtb = null;
            BitmapFrame bf = null;
            try
            {
                rtb = RenderVisaulToBitmap(vsual, widhth, height);
                bf = BitmapFrame.Create(rtb);
                encoder.Frames.Add(bf);
                using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
                {
                    encoder.Save(fileStream);
                }

                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                encoder = null;
                bf = null;
                rtb = null;
            }
        }
Пример #15
0
		public static Color Convert(swm.Color value)
		{
			return new Color { A = value.A / 255f, R = value.R / 255f, G = value.G / 255f, B = value.B / 255f };
		}
 private sysMedia.Brush RotateImageBrush(sysMedia.Brush brush, int degree)
 {
     var bgBrush = brush.Clone();
     var transform = sysMedia.Matrix.Identity;
     transform.RotateAt(degree, 0.5, 0.5);
     if (bgBrush is sysMedia.ImageBrush)
     {
         bgBrush.RelativeTransform = new sysMedia.MatrixTransform(transform);
     }
     return bgBrush;
 }
Пример #17
0
		GraphicsPathHandler (swm.PathGeometry control)
		{
			Control = control;
		}
        private sysMedia.Brush ClipImageBrush(sysMedia.Brush brush, Rect regionRect)
        {
            var imgBrush = brush.Clone() as sysMedia.ImageBrush;

            if (imgBrush != null)
            {
                imgBrush.Viewbox = regionRect;//ToDo: need to consider the image is not a square.
                return imgBrush;
            }

            return new sysMedia.SolidColorBrush(sysMedia.Colors.Transparent);
        }
Пример #19
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null) {
                DrawingContext c = new DrawingContext (dc, scaleFactor);
                actx.InvokeUserCode (delegate {
                    drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height), idesc, actx.Toolkit);
                });
            }
            else {
                if (idesc.Alpha < 1)
                    dc.PushOpacity (idesc.Alpha);

                var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                var bmpImage = f as BitmapSource;

                // When an image is a single bitmap that doesn't have the same intrinsic size as the drawing size, dc.DrawImage makes a very poor job of down/up scaling it.
                // Thus we handle this manually by using a TransformedBitmap to handle the conversion in a better way when it's needed.

                var scaledWidth = idesc.Size.Width * scaleFactor;
                var scaledHeight = idesc.Size.Height * scaleFactor;
                if (bmpImage != null && (Math.Abs (bmpImage.PixelHeight - scaledHeight) > 0.001 || Math.Abs (bmpImage.PixelWidth - scaledWidth) > 0.001))
                    f = new TransformedBitmap (bmpImage, new ScaleTransform (scaledWidth / bmpImage.PixelWidth, scaledHeight / bmpImage.PixelHeight));

                dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                    dc.Pop ();
            }
        }
Пример #20
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null) {
                DrawingContext c = new DrawingContext (dc, scaleFactor);
                actx.InvokeUserCode (delegate {
                    drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height));
                });
            }
            else {
                if (idesc.Alpha < 1)
                    dc.PushOpacity (idesc.Alpha);

                var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                    dc.Pop ();
            }
        }
Пример #21
0
        public static BitmapSource ConvertNativePointerToBitmapSource(IntPtr pData, int w, int h, SWM.PixelFormat pixelFormat)
        {
            int ch = 1;

            if (pixelFormat == SWM.PixelFormats.Gray8) ch = 1; //grey scale image 0-255
            if (pixelFormat == SWM.PixelFormats.Bgr24) ch = 3; //RGB
            if (pixelFormat == SWM.PixelFormats.Bgr32) ch = 4; //RGB + alpha

            WriteableBitmap wbm = new WriteableBitmap(w, h, 96, 96, pixelFormat, null);
            CopyMemory(wbm.BackBuffer, pData, (uint)(w * h * ch));

            wbm.Lock();
            wbm.AddDirtyRect(new Int32Rect(0, 0, wbm.PixelWidth, wbm.PixelHeight));
            wbm.Unlock();

            return wbm;
        }
        public short Calculate(string imageFilePath, Polygon polygon, Media.PointCollection pointCollection)
        {
            // Maskiertes Bild laden
            // Drawing.Bitmap maskedBitmap = GetMaskedBitmap(imageFilePath, pointCollection);

            Image<Bgr, byte> cvImage = new Image<Bgr, byte>(imageFilePath);

            // Maske generieren aus Polygon
            Mat matMask = new Mat(new Drawing.Size(cvImage.Cols, cvImage.Rows), DepthType.Cv8U, 3);
            // Polygone skalieren und generieren
            List<Point> scaledPoints = GetScaledPoints(pointCollection, cvImage.Rows, cvImage.Cols);
            List<Drawing.Point> scaledDrawingPoints = GetPolygonPoints(scaledPoints, cvImage.Rows, cvImage.Cols);
            // Polygon weiss zeichnen
            using (VectorOfPoint vPoint = new VectorOfPoint(scaledDrawingPoints.ToArray()))
            using (VectorOfVectorOfPoint vvPoint = new VectorOfVectorOfPoint(vPoint))
            {
                CvInvoke.FillPoly(matMask, vvPoint, new Bgr(255, 255, 255).MCvScalar);
            }
            Image<Gray, byte> imageMask = new Image<Gray, byte>(matMask.Bitmap);

            // Durchschnittsfarbe rechnen mit Maske
            Bgr result = cvImage.GetAverage(imageMask);
            // Vergleichen mit Referenzbildern
            Bgr snow = JsonConvert.DeserializeObject<Bgr>(polygon.BgrSnow);
            Bgr normal = JsonConvert.DeserializeObject<Bgr>(polygon.BgrNormal);

            double resultSnow = Math.Abs(snow.Blue - result.Blue) + Math.Abs(snow.Green - result.Green) + Math.Abs(snow.Red - result.Red);
            double resultNormal = Math.Abs(normal.Blue - result.Blue) + Math.Abs(normal.Green - result.Green) + Math.Abs(normal.Red - result.Red);

            if (Math.Abs(resultSnow - resultNormal) < 10)
            {
                return 0;
            }
            else if (resultSnow < resultNormal)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }