Exemplo n.º 1
0
		private void Build(PivotCollection collection, Stream stream)
		{
			try
			{
				int mortonStart = MortonHelpers.LevelXYToMortonStart(Level, X, Y, AllTileDefaults.CollectionTileMaxLevel);

				// Draw the sub-tiles into the tile
				int subTileCount = MortonHelpers.LevelToSubTileCount(Level, AllTileDefaults.CollectionTileMaxLevel);
				int subTileSize = AllTileDefaults.CollectionTileSize / subTileCount;
				using (CollectionTile tile = new CollectionTile(AllTileDefaults.CollectionTileSize, subTileSize))
				{
					for (int subTileX = 0; subTileX < subTileCount; ++subTileX)
					{
						for (int subTileY = 0; subTileY < subTileCount; ++subTileY)
						{
							int uniqueID = mortonStart + MortonHelpers.XYToMorton(subTileX, subTileY);
							Item item = collection.FindItem(uniqueID);
							if (item == null)
								continue;
							ImageProviderBase imageProvider = item.ItemImage.GetImageProvider();
							tile.Draw(imageProvider, subTileX * subTileSize, subTileY * subTileSize);
						}
					}

					tile.Save(stream, ImageFormat.Png);
				}
			}
			catch (Exception ex)
			{
				ex.GetType();
			}
		}
Exemplo n.º 2
0
		private bool UpdateLevel(int imageID, int level, int maxLevel, ImageProviderBase imageProvider)
		{
			ImageFormat fileFormat = (_fileFormat == "png" ? ImageFormat.Png : ImageFormat.Jpeg);
			int subTileCount = MortonHelpers.LevelToSubTileCount(level, maxLevel);

			try
			{
				if (_buildCollectionTiles)
				{
					int tileX, tileY, subTileX, subTileY;
					MortonHelpers.MortonBreakdown(imageID, level, maxLevel, out tileX, out tileY, out subTileX, out subTileY);
					int subTileSize = _tileSize / subTileCount;

					string tilePath = GetTilePath(_fileFormat, level, tileX, tileY);
					if (_missingTilesOnly && File.Exists(tilePath))
						return false;

					ImageProvider.FolderPrep(tilePath);
					using (FileStream fileStream = new FileStream(tilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
					{
						using (CollectionTile tile = new CollectionTile(_tileSize, subTileSize))
						{
							if (fileStream.Length > 0)
							{
								tile.Load(fileStream);
								fileStream.Position = 0;
							}

							tile.Draw(imageProvider, subTileX * subTileSize, subTileY * subTileSize);
							tile.Save(fileStream, fileFormat);

							string publishedTilePath = GetPublishPathFromMasterPath(tilePath);
							if (File.Exists(publishedTilePath))
								File.Delete(publishedTilePath);
						}
					}

					return true;
				}
				else
				{
					int dimension = subTileCount * _tileSize;
					int numTilesX = (imageProvider.Size.Width - 1) / dimension;
					int numTilesY = (imageProvider.Size.Height - 1) / dimension;

					bool ok = false;
					for (int tileX = 0; tileX <= numTilesX; tileX++)
					{
						for (int tileY = 0; tileY <= numTilesY; tileY++)
						{
							string tilePath = GetTilePath(_fileFormat, level, tileX, tileY);
							if (_missingTilesOnly && File.Exists(tilePath))
								continue;

							ImageProvider.FolderPrep(tilePath);
							using (FileStream fileStream = new FileStream(tilePath, FileMode.Create, FileAccess.Write))
							{
								using (DziTile tile = new DziTile(_tileSize))
								{
									tile.Draw(imageProvider, level, tileX, tileY);
									tile.Save(fileStream, fileFormat);
								}
							}

							ok |= true;
						}
					}

					return ok;
				}
			}
			catch (Exception ex)
			{
				ex.GetType();
			}

			return false;
		}