private static bool CacheImage(string originalPath, string fileName, string cacheFolder, PictureSize thumbnailImageSize, ScaleMode scaleMode, bool useBgImage, int delta) { string sourcePath = Path.Combine(HttpContext.Current.Server.MapPath(originalPath), fileName); Bitmap image; using (FileStream stream = new FileStream(sourcePath, FileMode.Open)) { image = new Bitmap(stream); } string cachePath = HttpContext.Current.Server.MapPath("~/ImageCache/" + cacheFolder); if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); string cachedImagePath = Path.Combine(cachePath, fileName); using (FileStream stream = new FileStream(cachedImagePath, FileMode.CreateNew)) { return ScaleImage(cacheFolder, image, new Size(thumbnailImageSize.Width, thumbnailImageSize.Height), stream, scaleMode, useBgImage, delta); } }
private static bool CacheImage(string fileName, string cacheFolder, PictureSize thumbnailImageSize, ScaleMode scaleMode, bool useBgImage, int delta) { string sourcePath = Path.Combine(HttpRuntime.AppDomainAppPath, "Content", "Images", fileName); Bitmap image; using (FileStream stream = new FileStream(sourcePath, FileMode.Open)) { image = new Bitmap(stream); } string cachePath = Path.Combine(HttpRuntime.AppDomainAppPath, "ImageCache", cacheFolder); if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); string cachedImagePath = Path.Combine(cachePath, fileName); using (FileStream stream = new FileStream(cachedImagePath, FileMode.CreateNew)) { return ScaleImage(cacheFolder, image, new Size(thumbnailImageSize.Width, thumbnailImageSize.Height), stream, scaleMode, useBgImage, delta); } }