Example #1
0
		public void Draw(ImageProviderBase imageProvider, int x, int y)
		{
			try
			{
				if (imageProvider == null || imageProvider.Image == null)
					return;

				Size size = imageProvider.Size;
				while (Math.Max(size.Width, size.Height) > _subTilesize)
				{
					if ((size.Width & 1) == 1) size.Width++;
					size.Width /= 2;
					if ((size.Height & 1) == 1) size.Height++;
					size.Height /= 2;
				}

				if (size.Width == 0) size.Width = 1;
				if (size.Height == 0) size.Height = 1;

				Rectangle dstRect = new Rectangle(x, y, size.Width, size.Height);
				_graphics.FillRectangle(AllTileDefaults.BackgroundBrush, x, y, size.Width, size.Height);
				double rate = Scale.ScaleToFit(ref dstRect, imageProvider.Image.Width, imageProvider.Image.Height,
					AllTileDefaults.TileFill, AllTileDefaults.TileUpsizing, AllTileDefaults.TileMarginPercent,
					AllTileDefaults.TileHorizontalAlignment, AllTileDefaults.TileVerticalAlignment);

				_graphics.DrawImage(imageProvider.Image, dstRect);
				// Cover up and over-painting
				_graphics.FillRectangle(Brushes.Black, x + size.Width, y, _subTilesize - size.Width, _subTilesize);
				_graphics.FillRectangle(Brushes.Black, x, y + size.Height, _subTilesize, _subTilesize - size.Height);
			}
			catch (Exception ex)
			{
				ex.GetType();
			}
		}
Example #2
0
		public void Draw(ImageProviderBase imageProvider, int level, int tileX, int tileY)
		{
			try
			{
				if (imageProvider == null)
					return;

				double maxTileSize = Math.Pow(2, level);
				Size size = imageProvider.Size;
				while (Math.Max(size.Width, size.Height) > maxTileSize)
				{
					if ((size.Width & 1) == 1) size.Width++;
					size.Width /= 2;
					if ((size.Height & 1) == 1) size.Height++;
					size.Height /= 2;
				}

				if (size.Width == 0) size.Width = 1;
				if (size.Height == 0) size.Height = 1;

				int overhangX = tileX * _tileSize;
				int overhangY = tileY * _tileSize;

				Size bitmapSize = new Size(Math.Min(size.Width - overhangX, _tileSize), Math.Min(size.Height - overhangY, _tileSize));
				_bitmapOutput = new Bitmap(bitmapSize.Width, bitmapSize.Height);
				_bitmapOutput.SetResolution(100, 100);

				_graphics = Graphics.FromImage(_bitmapOutput);
				_graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
				_graphics.SmoothingMode = SmoothingMode.None;
				_graphics.PageUnit = GraphicsUnit.Pixel;
				_graphics.FillRectangle(AllTileDefaults.BackgroundBrush, 0, 0, _bitmapOutput.Width, _bitmapOutput.Height);

				if (imageProvider.Image == null)
					return;

				Rectangle dstRect = new Rectangle(-overhangX, -overhangY, size.Width, size.Height);
				double rate = Scale.ScaleToFit(ref dstRect, imageProvider.Image.Width, imageProvider.Image.Height,
					AllTileDefaults.TileFill, AllTileDefaults.TileUpsizing, AllTileDefaults.TileMarginPercent,
					AllTileDefaults.TileHorizontalAlignment, AllTileDefaults.TileVerticalAlignment);

				_graphics.DrawImage(imageProvider.Image, dstRect);
			}
			catch (Exception ex)
			{
				ex.GetType();
			}
		}
Example #3
0
		public bool Serve(HttpContext context, ImageProviderBase imageProvider, bool cacheToDisk)
		{
			if (imageProvider == null)
				return false;

			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (DziTile tile = new DziTile(AllTileDefaults.DziTileSize))
				{
					tile.Draw(imageProvider, Level, X, Y);
					tile.Save(memoryStream, ImageFormat.Jpeg);
					memoryStream.Position = 0; // Rewind the stream, ready for reading
					memoryStream.WriteTo(context.Response.OutputStream);
					context.Response.ContentType = "image/jpeg";
					if (cacheToDisk)
						CacheFile.Save(memoryStream, CachePath);
				}
			}

			return true;
		}
Example #4
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;
		}