Exemplo n.º 1
0
        private FreeImageAlgorithmsBitmap Stitch(int stitchWidth, int stitchHeight)
        {
            float zoom = 1.0f;
            Point origin = new Point(0, 0);

            List<Tile> tiles = null;

            RoiTool roiPlugin = this.Window.GetTool("Region") as RoiTool;

            Rectangle roi = Rectangle.Empty;

            if(roiPlugin.Active == true)
                roi = roiPlugin.TransformedRegionOfInterest;

            if (roi != null && roi != Rectangle.Empty)
            {
                tiles = new List<Tile>();

                foreach (Tile tile in MosaicWindow.MosaicInfo.Items)
                {
                    if (roi.IntersectsWith(tile.Bounds))
                    {
                        tiles.Add(tile);
                    }
                }

                zoom = (float)stitchWidth / (float)(roi.Width);
                origin = roi.Location;
            }
            else
            {
                tiles = new List<Tile>(MosaicWindow.MosaicInfo.Items);
                zoom = (float)stitchWidth / (float)(MosaicWindow.MosaicInfo.TotalWidth);
            }

               // origin = Tile.GetOriginOfTiles(tiles);

            //int width = Tile.GetHorizontalRangeOfTiles(tiles);
            //int height = Tile.GetVerticalRangeOfTiles(tiles);

            int width, height;

            if (roi == Rectangle.Empty)
            {
                // Whole mosaic Width / Height
                width = MosaicWindow.MosaicInfo.TotalWidth;
                height = MosaicWindow.MosaicInfo.TotalHeight;
            }
            else
            {
                width = roi.Width;
                height = roi.Height;
            }

            FreeImageAlgorithmsBitmap section = null;

            try
            {
                section = new FreeImageAlgorithmsBitmap((int)(width * zoom), (int)(height * zoom),
                    MosaicWindow.MosaicInfo.FreeImageType, MosaicWindow.MosaicInfo.ColorDepth);
            }
            catch (FreeImageException)
            {
                return null;
            }

            FreeImageAlgorithmsBitmap tmpBitmap = null;

            int count = 1;

            foreach (Tile tile in tiles)
            {
                Point position = tile.GetTilePositionRelativeToPoint(origin);

                position.X = (int)(position.X * zoom);
                position.Y = (int)(position.Y * zoom);

                try
                {
                    tmpBitmap = tile.LoadFreeImageBitmap((int)(tile.Width * zoom), (int)(tile.Height * zoom));
                }
                catch (FreeImageException e)
                {
                    MessageBox.Show(e.Message);
                }

                section.PasteFromTopLeft(tmpBitmap, position, this.Window.BlendingEnabled);

                tmpBitmap.Dispose();

                this.threadController.ReportThreadPercentage(this, "Saving Tiles",
                    count, tiles.Count);

                count++;
            }

            return section;
        }
Exemplo n.º 2
0
        public static void PasteTile(FreeImageAlgorithmsBitmap dst, 
                                     FreeImageAlgorithmsBitmap src, Point location, bool blending)
        {
            if (blending)
            {
                if (!dst.GradientBlendPasteFromTopLeft(src, location))
                {
                    string errorStr = String.Format(
                        "Can not paste freeimage. Dst image bpp {0}, Src image bpp {1}",
                        dst.ColorDepth, src.ColorDepth);

                    throw new FormatException(errorStr);
                }
            }
            else
            {
                if (!dst.PasteFromTopLeft(src, location))
                {
                    string errorStr = String.Format(
                        "Can not paste freeimage. Dst image bpp {0}, Src image bpp {1}",
                        dst.ColorDepth, src.ColorDepth);

                    throw new FormatException(errorStr);
                }
            }
        }