示例#1
0
        /// <summary>
        /// 组合图片
        /// </summary>
        /// <param name="fileName">保存文件名称</param>
        /// <param name="format">图片格式</param>
        /// <param name="zeroPoint">地图0点坐标位置</param>
        public void Compose(string fileName, ImageFormat format, ZeroPoint zeroPoint)
        {
            float xCount = this.End.X - this.Start.X;
            float yCount = this.End.Y - this.Start.Y;

            //垂直方向碎片总数
            int VerticalSizeCount = (int)Math.Abs(yCount);
            //水平方向总数
            int HorizontalSizeCount = (int)Math.Abs(xCount);

            //构建瓦片拼接的最终地图
            Bitmap map = new Bitmap(
                //水平方向元素总数*单个碎片图像宽度
                HorizontalSizeCount * (int)this.FragmentSize.Width,
                //垂直方向元素总数*单个碎片图片高度
                VerticalSizeCount * (int)this.FragmentSize.Height);

            //GDI+画图
            Graphics tempGraphics = Graphics.FromImage(map);

            //逐行循环
            for (int i = 0; i < HorizontalSizeCount; i++)
            {
                //逐列循环
                for (int j = 0; j < VerticalSizeCount; j++)
                {
                    //碎片绘制位置
                    Vectory2D point = new Vectory2D();
                    point.X = i * this.FragmentSize.Width;
                    point.Y = j * this.FragmentSize.Height;

                    //得到线性内存表的偏移量公式:偏移量=每行列数*当前行+当前列
                    int offset = VerticalSizeCount * i + j;

                    //从缓存碎片拼接图片
                    string cacheMapPath = MapFragments[offset].SavePath + "\\" + MapFragments[offset].FileName;
                    using (Bitmap cacheMap = new Bitmap(cacheMapPath))
                    {
                        //将碎片绘制到内存
                        //绘图0点坐标左上角;地图0点坐标左下角
                        switch (zeroPoint)
                        {
                            case ZeroPoint.LeftBottom:
                                tempGraphics.DrawImage(
                                    //MapFragments[offset].Image,
                                    cacheMap,
                                    point.X,
                                    AreaSize.Height - point.Y - this.FragmentSize.Height);
                                break;
                            case ZeroPoint.LeftTop:
                                tempGraphics.DrawImage(
                                    //MapFragments[offset].Image,
                                    cacheMap,
                                    point.X,
                                    point.Y);
                                break;
                        }
                    }
                }
            }

            //保存
            tempGraphics.Dispose();

            FileInfo fileInfo = new FileInfo(fileName);
            if (!Directory.Exists(fileInfo.DirectoryName))
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }
            map.Save(fileName, format);
        }
示例#2
0
        /// <summary>
        /// 组合图片
        /// </summary>
        /// <param name="fileName">保存文件名称</param>
        /// <param name="format">图片格式</param>
        /// <param name="zeroPoint">地图0点坐标位置</param>
        public void Compose(string fileName, ImageFormat format, ZeroPoint zeroPoint)
        {
            float xCount = this.End.X - this.Start.X;
            float yCount = this.End.Y - this.Start.Y;

            //垂直方向碎片总数
            int VerticalSizeCount = (int)Math.Abs(yCount);
            //水平方向总数
            int HorizontalSizeCount = (int)Math.Abs(xCount);

            //构建瓦片拼接的最终地图
            Bitmap map = new Bitmap(
                //水平方向元素总数*单个碎片图像宽度
                HorizontalSizeCount * (int)this.FragmentSize.Width,
                //垂直方向元素总数*单个碎片图片高度
                VerticalSizeCount * (int)this.FragmentSize.Height);

            //GDI+画图
            Graphics tempGraphics = Graphics.FromImage(map);

            //逐行循环
            for (int i = 0; i < HorizontalSizeCount; i++)
            {
                //逐列循环
                for (int j = 0; j < VerticalSizeCount; j++)
                {
                    //碎片绘制位置
                    Vectory2D point = new Vectory2D();
                    point.X = i * this.FragmentSize.Width;
                    point.Y = j * this.FragmentSize.Height;

                    //得到线性内存表的偏移量公式:偏移量=每行列数*当前行+当前列
                    int offset = VerticalSizeCount * i + j;

                    //从缓存碎片拼接图片
                    string cacheMapPath = MapFragments[offset].SavePath + "\\" + MapFragments[offset].FileName;
                    using (Bitmap cacheMap = new Bitmap(cacheMapPath))
                    {
                        //将碎片绘制到内存
                        //绘图0点坐标左上角;地图0点坐标左下角
                        switch (zeroPoint)
                        {
                        case ZeroPoint.LeftBottom:
                            tempGraphics.DrawImage(
                                //MapFragments[offset].Image,
                                cacheMap,
                                point.X,
                                AreaSize.Height - point.Y - this.FragmentSize.Height);
                            break;

                        case ZeroPoint.LeftTop:
                            tempGraphics.DrawImage(
                                //MapFragments[offset].Image,
                                cacheMap,
                                point.X,
                                point.Y);
                            break;
                        }
                    }
                }
            }

            //保存
            tempGraphics.Dispose();

            FileInfo fileInfo = new FileInfo(fileName);

            if (!Directory.Exists(fileInfo.DirectoryName))
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }
            map.Save(fileName, format);
        }