Ejemplo n.º 1
1
      static public ImageProcessingResult Process(string imageName, IBinaryRepository binaryRepository)
      {
         var log = new EventLog("Application")
         {
            Source = "Tadmap"
         };

         log.WriteEntry("Processing image:" + imageName, EventLogEntryType.Information);

         Stream binary = binaryRepository.GetBinary(imageName);

         if (binary == null)
         {
            log.WriteEntry("No binary found:" + imageName, EventLogEntryType.Warning);
            return new ImageProcessingResult { Key = imageName, Result = ImageProcessingResult.ResultType.Failed }; // Image not available in the queue yet.
         }

         // If I have an image I should renew the message.

         IImageSet imageSet = new ImageSet1(imageName);

         int zoomLevels;
         int tileSize;
         imageSet.Create(binary, binaryRepository, out zoomLevels, out tileSize);
         log.WriteEntry("Processing finished.", EventLogEntryType.Information);

         return new ImageProcessingResult
         {
            Key = imageName,
            Result = ImageProcessingResult.ResultType.Complete,
            ZoomLevel = zoomLevels,
            TileSize = tileSize
         };
      }
Ejemplo n.º 2
0
      public void CreateTileSet(IBinaryRepository binaryRepository)
      {
         System.Drawing.Image oImage = Bitmap.FromStream(binaryRepository.GetBinary(StorageKey));

         double iZoomLevel = 0;
         double iMaxDimension = Math.Max(oImage.Width, oImage.Height);
         int iTileSize = Convert.ToInt32(iMaxDimension);

         while (iTileSize > 359)
         {
            iZoomLevel++;
            iTileSize = Convert.ToInt32(iMaxDimension / Math.Pow(2, iZoomLevel));
         }

         ZoomLevels = Convert.ToInt32(iZoomLevel);
         TileSize = iTileSize;

         int iImageSize = Convert.ToInt32(iMaxDimension);
         Bitmap oBaseImage = ImageManipulator.CenterImage(oImage as Bitmap, iImageSize, iImageSize);

         while (iZoomLevel >= 0)
         {
            iImageSize = Convert.ToInt32(iTileSize * Math.Pow(2, iZoomLevel));
            using (Bitmap oZoomedImage = ImageManipulator.Resize(oBaseImage, iImageSize, iImageSize))
            {
               List<List<Bitmap>> oTiles = ImageManipulator.CreateTiles(oZoomedImage, iTileSize);

               for (int i = 0; i < oTiles.Count; i++)
               {
                  for (int j = 0; j < oTiles[i].Count; j++)
                  {
                     bool bUploaded = false;
                     int tryCount = 0;

                     while (bUploaded == false && tryCount < 3)
                     {
                        try
                        {
                           using (MemoryStream oStream = new MemoryStream())
                           {

                              oTiles[i][j].Save(oStream, System.Drawing.Imaging.ImageFormat.Png);
                              oStream.Position = 0;
                              binaryRepository.Add(
                                 oStream,
                                 string.Format(CultureInfo.InvariantCulture, "Tile_{0}_{1}_{2}_{3}", j, i, iZoomLevel, mStorageKey),
                                 "image.jpeg"
                              );

                              bUploaded = true;
                           }
                        }
                        catch (BinaryRepositoryException oException)
                        {
                           tryCount++;

                           if (tryCount > 3)
                           {
                              throw new BinaryRepositoryException("Failed to add tile on third attempt.", oException);
                           }
                        }
                     }
                  }
               }
            }

            iZoomLevel--;
         }
      }