public static Image GetImageById(string imageId) { Bitmap returnvalue = null; try { var path = ImagePath + imageId + "."; if (!imageCache.TryGetValue(path, out returnvalue)) { if (File.Exists(path + "jpg")) { returnvalue = (Bitmap)CT_Helper.resizeImage(Image.FromFile(path + "jpg", true), bitmapSize); } else if (File.Exists(path + "jpeg")) { returnvalue = (Bitmap)CT_Helper.resizeImage(Image.FromFile(path + "jpeg", true), bitmapSize); } imageCache.Add(path, returnvalue); } } catch (Exception) { } return(returnvalue); }
public Image DrawImage(Size size) { Dictionary <String, Bitmap> cache = new Dictionary <string, Bitmap>(); Bitmap returnvalue = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb); Graphics g = Graphics.FromImage(returnvalue); for (var x = 0; x < MapGrid.GridElementCollection.Length; x++) { var row = MapGrid.GridElementCollection[x]; for (var y = 0; y < row.Length; y++) { Bitmap image; var gridElement = row[y]; var elementWidth = (int)(Math.Ceiling((MapGrid.Width / row.Length) * getScaleFactorWidth(size.Width))); var elementHeight = (int)(Math.Ceiling((MapGrid.Height / MapGrid.GridElementCollection.Length) * getScaleFactorHeight(size.Height))); if (!cache.TryGetValue(gridElement.ImageId, out image)) { image = (Bitmap)MapParser.GetImageById(gridElement.ImageId); image = (Bitmap)CT_Helper.resizeImage(image, new Size(elementWidth, elementHeight)); cache.Add(gridElement.ImageId, image); } //image = (Bitmap)image.GetThumbnailImage(elementWidth, elementHeight, null, IntPtr.Zero); g.DrawImageUnscaled(image, elementWidth * x, elementHeight * y); /* for (var bx = 0; bx < elementWidth; bx++) * { * for (var by = 0; by < elementHeight; by++) * { * var cl = image.GetPixel(bx, by); * returnvalue.SetPixel(bx + (elementWidth * x), by + (elementHeight * y), cl); * } * } */ } } return(returnvalue); }