Exemplo n.º 1
0
        public UIElement CreateVisual(VirtualCanvas parent)
        {
            if (_visual == null && _tileBuf != null && _tileBuf.Length == TileWidth * TileHeight * 3)
            {
                ImageSource source = BitmapSource.Create(TileWidth, TileHeight, 96, 96,
                                                         PixelFormats.Rgb24, null, _tileBuf, TileWidth * 3);

                // Fill rectangle with an ImageBrush
                _rect.Fill = new ImageBrush(source); // StrideSize = 768 = 1 Tile * 3 Channels * 256 pixels

                _visual = _rect;
            }
            return(_visual);
        }
Exemplo n.º 2
0
        public UIElement CreateVisual(VirtualCanvas parent)
        {
            if (_visual == null)
            {
                byte[] targetBuffer = new byte[256 * 256 * 3];

                //      var stopWatch = Stopwatch.StartNew();

                // 【期待加速】

                //      Task t1 = Task.Factory.StartNew(() =>
                //      {
                //          MemoryStream stream1 = new MemoryStream(_tileTiffBuffer, false);
                //          TiffStream streamTIFF1 = new TiffStream();
                //          Tiff tiff_file = Tiff.ClientOpen("In-Memory-Target", "r", stream1, streamTIFF1);

                _inputTiffFile.SetDirectory((short)_currentPage);     // page必须为short类型
                int tile_width  = _inputTiffFile.GetField(TiffTag.TILEWIDTH)[0].ToInt();
                int image_width = _inputTiffFile.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
                int tile_xCount = image_width / tile_width;
                _inputTiffFile.ReadEncodedTile(_xGrid + _yGrid * tile_xCount, targetBuffer, 0, tile_width * tile_width * 3);
                //        });

                //      t1.Wait();


                //  耗时 10ms - 12ms
                //        Console.WriteLine("1加载1个tile耗时 = {0} us\n", stopWatch.Elapsed.TotalSeconds * 1000000);

                // 耗时 200us
                ImageBrush imgBrush = new ImageBrush(BitmapSource.Create(256, 256, 96d, 96d,
                                                                         PixelFormats.Rgb24, null, targetBuffer, 768)); // StrideSize = 768 = 1 Tile * 3 Channels * 256 pixels

                // Fill rectangle with an ImageBrush
                _rect.Fill = imgBrush;
                _visual    = _rect;

                /*********************************** 多线程更新  *************************************/
                //   Action<UIElement,ImageBrush> updateAction = new Action<UIElement, ImageBrush>(UpdateShape);
                //   parent.Dispatcher.BeginInvoke(updateAction, _visual,  imgBrush);

                //   Task.Factory.StartNew(() => UpdateShape(_visual, imgBrush),
                //      new CancellationTokenSource().Token, TaskCreationOptions.None, _syncContextTaskScheduler).Wait();

                //   Task.Factory.StartNew(() => UpdateShape(_visual, imgBrush), new CancellationTokenSource().Token).Wait();
            }
            return(_visual);
        }
Exemplo n.º 3
0
        public Byte[] AcquireVisualData(VirtualCanvas parent)
        {
            Byte[]       targetBuffer = new byte[256 * 256 * 3];
            MemoryStream stream1      = new MemoryStream(_tileTiffBuffer, false);
            TiffStream   streamTIFF1  = new TiffStream();
            Tiff         tiff_file    = Tiff.ClientOpen("In-Memory-Target", "r", stream1, streamTIFF1);

            tiff_file.SetDirectory((short)_currentPage); // page必须为short类型
            int tile_width  = tiff_file.GetField(TiffTag.TILEWIDTH)[0].ToInt();
            int image_width = tiff_file.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
            int tile_xCount = image_width / tile_width;

            tiff_file.ReadEncodedTile(_xGrid + _yGrid * tile_xCount, targetBuffer, 0, tile_width * tile_width * 3);


            return(targetBuffer);
        }
Exemplo n.º 4
0
        public bool FillVisualData(VirtualCanvas parent)
        {
            int offset = 0;

            if (_tileBuf == null && _currentPage == 1)
            {
                _tileBuf = new byte[TileWidth * TileHeight * 3];

                int _xGrid = (int)(_bounds.X / TileWidth);
                int _yGrid = (int)(_bounds.Y / TileHeight);

                Tiff tiff_file = Tiff.ClientOpen("In-Memory-Target", "r", new MemoryStream(_tiffFileBuffer, false), new TiffStream());

                tiff_file.SetDirectory((short)_currentPage); // page必须为short类型
                int tile_width  = tiff_file.GetField(TiffTag.TILEWIDTH)[0].ToInt();
                int image_width = tiff_file.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
                // int tile_width = 66 * 256/4;
                // int image_width = 65 * 256/4;
                int tile_xCount = image_width / tile_width / 4;
                if (tile_xCount * tile_width < image_width)
                {
                    offset = 1;
                }
                //creatVisualFromDisk(_xGrid, _yGrid,out _tileBuf,(int) _currentPage);如果想从文件夹里面读取要这样
                int result = tiff_file.ReadEncodedTile(_xGrid + _yGrid * (tile_xCount + offset), _tileBuf, 0, tile_width * tile_width * 3);

                if (_tileBuf.Length != TileWidth * TileHeight * 3)
                {
                    return(false);   // _tileBuf is loaded with error.
                }
                else
                {
                    return(true);
                }
            }
            else if (_tileBuf == null && _currentPage == 0)
            {
                _tileBuf = new byte[TileWidth * TileHeight * 3];

                int _xGrid = (int)(_bounds.X / TileWidth);
                int _yGrid = (int)(_bounds.Y / TileHeight);

                Tiff tiff_file = Tiff.ClientOpen("In-Memory-Target", "r", new MemoryStream(_tiffFileBuffer, false), new TiffStream());

                tiff_file.SetDirectory((short)_currentPage); // page必须为short类型
                int tile_width  = tiff_file.GetField(TiffTag.TILEWIDTH)[0].ToInt();
                int image_width = tiff_file.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
                //int tile_width = 66 * 256 ;
                // int image_width = 65 * 256;
                int tile_xCount = image_width / tile_width;
                if (tile_xCount * tile_width < image_width)
                {
                    offset = 1;
                }
                //creatVisualFromDisk(_xGrid, _yGrid, out _tileBuf, (int)_currentPage);
                int result = tiff_file.ReadEncodedTile(_xGrid + _yGrid * (tile_xCount + offset), _tileBuf, 0, tile_width * tile_width * 3);

                if (_tileBuf.Length != TileWidth * TileHeight * 3)
                {
                    return(false);   // _tileBuf is loaded with error.
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);  // _tileBuf is filled before;
            }
        }
Exemplo n.º 5
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ScrollImageViewer = ((System.Windows.Controls.ScrollViewer)(target));

            #line 18 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.ScrollImageViewer.PreviewKeyDown += new System.Windows.Input.KeyEventHandler(this.ScrollImageViewer_PreviewKeyDown);

            #line default
            #line hidden
                return;

            case 2:
                this.gridViewer = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.gridContainer = ((System.Windows.Controls.Grid)(target));

            #line 22 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.gridContainer.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(this.OnPreviewMouseMove);

            #line default
            #line hidden
                return;

            case 4:
                this.imageCanvas = ((VirtualCanvasLib.VirtualCanvas)(target));
                return;

            case 5:
                this.annotationCanvas = ((DrawToolsLib.DrawingCanvas)(target));
                return;

            case 6:
                this.magnifierCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 7:
                this.magnifierEllipse = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 8:
                this.vbMagnifier = ((System.Windows.Media.VisualBrush)(target));
                return;

            case 9:
                this.labelImageCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 10:
                this.zoombarCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 11:
                this.btnZoomFit = ((System.Windows.Controls.Button)(target));

            #line 61 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoomFit.Click += new System.Windows.RoutedEventHandler(this.btnZoomFit_Click);

            #line default
            #line hidden
                return;

            case 12:
                this.btnZoom1x = ((System.Windows.Controls.Button)(target));

            #line 66 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoom1x.Click += new System.Windows.RoutedEventHandler(this.btnZoom1x_Click);

            #line default
            #line hidden
                return;

            case 13:
                this.btnZoom2x = ((System.Windows.Controls.Button)(target));

            #line 71 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoom2x.Click += new System.Windows.RoutedEventHandler(this.btnZoom2x_Click);

            #line default
            #line hidden
                return;

            case 14:
                this.btnZoom4x = ((System.Windows.Controls.Button)(target));

            #line 76 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoom4x.Click += new System.Windows.RoutedEventHandler(this.btnZoom4x_Click);

            #line default
            #line hidden
                return;

            case 15:
                this.btnZoom5x = ((System.Windows.Controls.Button)(target));

            #line 81 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoom5x.Click += new System.Windows.RoutedEventHandler(this.btnZoom5x_Click);

            #line default
            #line hidden
                return;

            case 16:
                this.btnZoom10x = ((System.Windows.Controls.Button)(target));

            #line 86 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoom10x.Click += new System.Windows.RoutedEventHandler(this.btnZoom10x_Click);

            #line default
            #line hidden
                return;

            case 17:
                this.btnZoom20x = ((System.Windows.Controls.Button)(target));

            #line 91 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.btnZoom20x.Click += new System.Windows.RoutedEventHandler(this.btnZoom20x_Click);

            #line default
            #line hidden
                return;

            case 18:
                this.zoomSlider = ((System.Windows.Controls.Slider)(target));

            #line 98 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.zoomSlider.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.zoomSlider_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 19:
                this.lbZoom = ((System.Windows.Controls.Label)(target));
                return;

            case 20:
                this.thumbnailCanvas = ((System.Windows.Controls.Canvas)(target));

            #line 106 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.thumbnailCanvas.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.thumbnailCanvas_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 21:
                this.thumbnailBorder = ((System.Windows.Controls.Border)(target));
                return;

            case 22:
                this.thumbnailZoomRectThumb = ((System.Windows.Controls.Primitives.Thumb)(target));

            #line 110 "..\..\..\ImageViewer\ImageViewer.xaml"
                this.thumbnailZoomRectThumb.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(this.thumbnailZoomRectThumb_DragDelta);

            #line default
            #line hidden
                return;

            case 23:
                this.ThumbnailImage_Brush = ((System.Windows.Media.ImageBrush)(target));
                return;
            }
            this._contentLoaded = true;
        }