private static void CreateCanvas(string baseurl, string geohex, IEnumerable<TileInfo> tiles, int width, int height, float hexLeft, float hexTop, int[] cols, int[] rows, bool isBase) { //create an object that will do the drawing operations int x = 0; int y = 0; int count = 0; int col = 0; int row = 0; string tile = string.Empty; using (var canvas = new Bitmap(width, height)) { using (var artist = Graphics.FromImage(canvas)) { artist.InterpolationMode = InterpolationMode.HighQualityBicubic; foreach (TileInfo tileInfo in tiles.OrderBy(t => t.Index.Col).ThenByDescending(t => t.Index.Row)) { if (count > 0) { x = Array.IndexOf(cols, tileInfo.Index.Col) * 256; y = Array.IndexOf(rows, tileInfo.Index.Row) * 256; } tile = string.Format("{0}/{1}/{2}/{3}.png", baseurl, tileInfo.Index.Level, tileInfo.Index.Col, tileInfo.Index.Row); //System.Diagnostics.Debug.WriteLine(tile); var request = WebRequest.Create(tile); using (var response = request.GetResponse()) { using (var stream = response.GetResponseStream()) { var imageTile = Bitmap.FromStream(stream); artist.DrawImage(imageTile, new PointF(x, y)); } } col = tileInfo.Index.Col; row = tileInfo.Index.Row; count++; } //Dibujo el Hexágono if (includeHexagon) { PointF[] points = new PointF[7]; points.SetValue(new PointF(hexLeft + 0, hexTop + 32f), 0); points.SetValue(new PointF(hexLeft + 19f, hexTop + 0), 1); points.SetValue(new PointF(hexLeft + 54f, hexTop + 0), 2); points.SetValue(new PointF(hexLeft + 73f, hexTop + 32f), 3); points.SetValue(new PointF(hexLeft + 54f, hexTop + 64f), 4); points.SetValue(new PointF(hexLeft + 19f, hexTop + 64f), 5); points.SetValue(new PointF(hexLeft + 0, hexTop + 32f), 6); SolidBrush fillbrush = new SolidBrush(Color.FromArgb(0, 255, 165, 0)); SolidBrush borderbrush = new SolidBrush(Color.FromArgb(255, 0, 128, 0)); artist.FillPolygon(fillbrush, points); artist.DrawPolygon(new Pen(borderbrush, 5), points); artist.Save(); } } try { //Crop y Márgenes int rectx = 0; if (width > 256) { rectx = (int)hexLeft - 74; } if (rectx < 0) rectx = 0; int recty = 0; if (height > 256) { recty = (int)hexTop - 80; } if (recty < 0) recty = 0; Rectangle cropArea = new Rectangle(rectx, recty, 256, 256); string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SatelliteImages", includeHexagon ? "demand" : "game1", string.Format("{0}{1}.jpg", geohex, isBase ? "-a" : "-d")); using (Bitmap canvasCropped = canvas.Clone(cropArea, canvas.PixelFormat)) { //canvasCropped.Save(filePath, ImageFormat.Jpeg); canvasCropped.Save(filePath, jgpEncoder, myEncoderParameters); } //Quedo obsoleto al no tener que usar Azure /* //Azure Blob string filePath = string.Format("{0}{1}.jpg", geohex, isBase ? "-a" : "-d"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(filePath); // Create or overwrite the "myblob" blob with contents from a local file. using (var fileStream = new System.IO.MemoryStream()) { using (Bitmap canvasCropped = canvas.Clone(cropArea, canvas.PixelFormat)) { //canvasCropped.Save(fileStream, ImageFormat.Jpeg); canvasCropped.Save(fileStream, jgpEncoder, myEncoderParameters); } fileStream.Position = 0; blockBlob.UploadFromStream(fileStream); } * */ } catch (Exception ex) { throw ex; } } }
/// <summary> /// Generate 2D data for preview pane. /// </summary> private void Generate2D() { ArrayList tempArray = new ArrayList(); double xMin = 0; double xMax = 0; double yMin = 0; double yMax = 0; foreach (Curve c in Profile) { List<XYZ> xyzArray = c.Tessellate() as List<XYZ>; foreach (Autodesk.Revit.DB.XYZ xyz in xyzArray) { Autodesk.Revit.DB.XYZ temp = new Autodesk.Revit.DB.XYZ (xyz.X, -xyz.Y, xyz.Z); FindMinMax(temp, ref xMin, ref xMax, ref yMin, ref yMax); tempArray.Add(temp); } } MaxLength = ((xMax - xMin) > (yMax - yMin)) ? (xMax - xMin) : (yMax - yMin); Points = new PointF[tempArray.Count / 2 + 1]; for (int i = 0; i < tempArray.Count; i = i + 2) { Autodesk.Revit.DB.XYZ point = (Autodesk.Revit.DB.XYZ)tempArray[i]; Points.SetValue(new PointF((float)(point.X - xMin), (float)(point.Y - yMin)), i / 2); } PointF end = (PointF)Points.GetValue(0); Points.SetValue(end, tempArray.Count / 2); }